Pulling part of content from a site

Discussion in 'PHP' started by ItamarP, Jun 27, 2009.

  1. #1
    Hi there , there's a movies review site and i want to write a code so i will be able to pull only the review part from the movie's page

    every movie has its own page and thats how it looks like :

    Movie's name
    pic
    actors

    review

    producer

    etc...



    I want to pull only the "review" section , i know i can use "file get contents" , but how can i pull only the review section each time ?
     
    ItamarP, Jun 27, 2009 IP
  2. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    look for a standard string before and after the text that you want to pull, then extract it from the text you get using the file_get_contents function.

    for example:
    $whole_text = file_get_contents("file.html");
    $start_string = "Reviews:";//could be any thing else, even html code but must be unique
    $end_string = "end review";//look comment for $start_string
    $review = get_string_between($whole_text, $start_string , $end_string);
    //and dont worry, this is the get_string_between function :)
    function get_string_between($string, $start, $end){
            $string = " ".$string;
            $ini = strpos($string,$start);
            if ($ini == 0) return "";
            $ini += strlen($start);   
            $len = strpos($string,$end,$ini) - $ini;
            return substr($string,$ini,$len);
    }
    PHP:
    :cool:
     
    zeronese, Jun 27, 2009 IP
  3. www.amagit.com

    www.amagit.com Peon

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Always keep an eye on your page because, if the movie page layout changes, your page may need new standard strings.

    Remember too that each time someone views your page your server downloads a copy of the movie page. If it becomes too popular the movie site may become angry with you due to the extra bandwidth (especially since you are essentially taking their content too).
     
    www.amagit.com, Jun 27, 2009 IP
  4. DavidFa1976

    DavidFa1976 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not sure, but I think it's not really legal...
     
    DavidFa1976, Jun 27, 2009 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Is there not a way around this, for example couldn't you pull the data then store it in your own database and retrieve it from there.
     
    wd_2k6, Jun 28, 2009 IP
  6. ItamarP

    ItamarP Member

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    storing the data on my own database is an option too
    anyway i just wanna do it for practicing , i hope ill be able to use it in the future
     
    ItamarP, Jun 28, 2009 IP