How do I use this PHP script please?

Discussion in 'PHP' started by NAZAM.COM, Feb 19, 2006.

  1. #1
    Somebody gave me the script below to scrape Google.co.uk movie theater listings onto my site. I have saved the file as cinemas.php here and then accessing it from a HTML file, but it just says http://www.google.co.uk/movies?hl=en&near=&sort=1&q=

    I needed some help from the PHP gurus, as I'm not really an expert with the language: what do I do now? How do I use the script?

    Also, can I ask if it is likely the script will break from time to time? I realise it's a guess, because nobody knows how frequently Google will change their movie listings, but anybody? I installed another PHP script and am having to constantly change it every two weeks because the site it is pulling data from keeps changing their format.

    <?php
    $URL="<A href="http://www.google.co.uk/movies?hl=en&near=".urlencode($town)."&sort=1&q=".urlencode($moviename">http://www.google.co.uk/movies?hl=en&near=".urlencode($town)."&sort=1&q=".urlencode($moviename);
    echo $URL;
    // Where to Start grabbing and where to End grabbing
    $Start = "Film Showtimes";
    //$Start = "<a href=\"/movies?hl=en&near=";
    $End = "Language Tools";
    // Open the file
    //$file = fopen("$URL", "r");
    // Read the file
    $r = file_get_contents ($URL);
    // Grab just the contents we want
    $stuff = eregi("$Start(.*)$End", $r, $content);
    //echo $stuff;
     
    // Get rid of some rubbish we don't need.
    $allowedtags = "<b><br>";
     
    $content[1]= strip_tags ($content[1],$allowedtags);
    $content[1]=  str_replace("<b>", "<p><b>", $content[1]);
    $content[1]=  str_replace("IMDb", "", $content[1]);
    $content[1]=  str_replace("Map", "", $content[1]);
    $content[1]=  str_replace("<b>Today</b>", "<!--", $content[1]);
    $content[1]=  str_replace("&nbsp;reviews<p>", "-->", $content[1]);
    $content[1]=  str_replace("&nbsp;-&nbsp;Film rating&nbsp;-&nbsp;Film title", "", $content[1]);
    echo $content[1];
    ?>
    
    Code (markup):
    Thank you very much.
     
    NAZAM.COM, Feb 19, 2006 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Scraping is illegal, aint it?
     
    noppid, Feb 19, 2006 IP
  3. NAZAM.COM

    NAZAM.COM Well-Known Member

    Messages:
    487
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Sorry, I didn't know it was illegal! I just wanted to try integrating the movie theater listings into my website. I wanted to know what exactly to do to use the PHP script.
     
    NAZAM.COM, Feb 19, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Firstly you should use an include to pull the script into a php file.

    Also you need to set the moviename variable before the script is run.
     
    mad4, Feb 20, 2006 IP