1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Anyone up for a PHP challenge?

Discussion in 'PHP' started by Cartman, Mar 25, 2005.

  1. #1
    I have a piece of Javascript code I run that prints out a pull-down menu on my site. What I want to do is have the PHP run the Javascript, parse out the text/links, and create a stadard option pull-down menu - Making it a bit more search engine friendly. (And maybe just run this PHP script once a day using a cron job, instead of on each page load, for the sake of speed)

    I'm VERY new to PHP, and haven't coded in probably 10 years, so I'm hoping that someone here has something that I can plug-in-and-play with, instead of investing hundreds of hours writing something up myself. Thanks in advance!

    :D
     
    Cartman, Mar 25, 2005 IP
  2. jocs

    jocs Peon

    Messages:
    103
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you post your code or tell us where it is, it may be we'll be able help you.
     
    jocs, Mar 25, 2005 IP
  3. Cartman

    Cartman Active Member

    Messages:
    354
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    88
    #3
    <SCRIPT LANGUAGE="JavaScript" SRC="http://search.eventinventory.com/interface.cfm?win=no&client=2855&face=F&etype=3"></SCRIPT>
    Code (markup):
    This generates a pulldown showing all of our events.. You can see it in action at www.celebrityseats.com, underneath the Concerts header. Thanks!
     
    Cartman, Mar 25, 2005 IP
  4. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why don't you just include the HTML using include?

    J.D.
     
    J.D., Mar 25, 2005 IP
  5. Cartman

    Cartman Active Member

    Messages:
    354
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    88
    #5
    I'm not sure I follow? Maybe if you go to my site and look at the source, you might better understand what I'm trying to do? I actually have the JS in the HTML source, and it prints the drop-down for the users.. I know it can be done, because I see other sites doing the same thing, and if you look in their source, you see the ENTIRE list in an option list.

    PM me if you want an example of another site that's doing this, I don't want to post it out in the open here.. :)
     
    Cartman, Mar 25, 2005 IP
  6. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The script you are getting off that other site isn't really a script - all it does is just calling document.write. So, if you read the this content and then strip off all non-HTML, then the result could be inserted directly into your output. You may need to use some form of caching to make it work snappier, but otherwise this should work just fine.

    J.D.
     
    J.D., Mar 25, 2005 IP
  7. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here's what you need:

    $file= fopen("http://search.eventinventory.com/interface.cfm?win=no&client=2855&
    face=H", "r");
    
    while(!feof($file)) 
        $content .= fgets($file, 1024);
    
    fclose($file);
    
    preg_match_all("/document\\.write\\(\'([^\\)]+)\'\\);/", $content, $matches));
    
    echo($matches[1][0]);
    echo($matches[1][1]);
    PHP:
    Obviously, you will need to add some error checking before using this code. I would also output these two matches separately - one belongs in <head> and the other wherever you want it to be on the page.

    This code will not work if the format of the content you pull off that other website changes. I would make the regex more generic before putting this into production (e.g. add optional spaces, tabs, different quotes, etc).

    J.D.
     
    J.D., Mar 25, 2005 IP
  8. Cartman

    Cartman Active Member

    Messages:
    354
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    88
    #8
    Awesome, that definitely helps, I'll give it a shot and see what happens. What kind of error checking would you suggest? Thanks again!
     
    Cartman, Mar 26, 2005 IP
  9. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, you need to generate some content if you can't open that file, if you get an error reading the content and if the expression doesn't match. How you deal with these errors is specific to your app - you can generate and error, you can serve old content, you can have a placeholder box saying something along the lines of "temporarily unavailable", etc.

    You are working with a third-party website and you need to be prepared. Using server-side scripts give you the opportunity to deal with their problems. Right now, for example, all these combo boxes on your page simply don't work in FF and there's nothing you can do about it.

    J.D.
     
    J.D., Mar 26, 2005 IP
  10. Cartman

    Cartman Active Member

    Messages:
    354
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    88
    #10
    FF as in FireFox? So if you go to my main page, you're not seeing the pulldowns, just blank space between the paragraphs? Would that be because you have Javascript disabled maybe? I might have to d/l Firefox and see how it looks, because I had no idea that was a problem. :(

    ** I tried implementing your code and am getting the following error:
    Parse error: parse error, unexpected ')' in /home2/sitenamehere/public_html/test.php on line 10

    Code reads as follows:
    <?php
    $file= fopen("http://search.eventinventory.com/interface.cfm?win=no&client=2855& 
    face=H", "r"); 
    
    while(!feof($file)) 
        $content .= fgets($file, 1024); 
    
    fclose($file); 
    
    preg_match_all("/document\\.write\\(\'([^\\)]+)\'\\);/", $content, $matches)); 
    
    echo($matches[1][0]); 
    echo($matches[1][1]); 
    ?>
    Code (markup):
    (Also, what is the "r" for in the first line of code?)

    I inserted the code into the HTML as follows:
    <?php include('test.php'); ?>
    Code (markup):
    Am I missing something simple? It's been a LONG night and I'm just not seeing straight this morning.
     
    Cartman, Mar 26, 2005 IP
  11. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yes, FireFox. No, I have JavaScript enabled. The combo box simply doesn't work - it's there, but when I click on it, nothing happens.

    Save the code I quoted as a separate file and run it just to see if it works with your version of PHP (I did check it and made sure it works). Once you've got this, you can work on an include. Keep in mind that include is a special statement and it may not work as expected in some contexts (e.g. if you use parenthesis - read more on this in the docs on include).

    Open file stream for reading only.

    J.D.
     
    J.D., Mar 26, 2005 IP
  12. Cartman

    Cartman Active Member

    Messages:
    354
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    88
    #12
    That's exactly what I did.. My server is running PHP 4.3.10. I'll have to tinker with this when I have more time and see where I'm going wrong. Thanks for your help!
     
    Cartman, Mar 27, 2005 IP