www.webdeveloper.com
Results 1 to 3 of 3

Thread: file_get_contents + preg_match question

  1. #1
    Join Date
    Mar 2006
    Posts
    38

    Question file_get_contents + preg_match question

    I am using the file_get_contents to access data on a page that I was given permission to scrape.

    I am using the preg_match to find the data that I'm looking for in the markup.

    But when I print the scrapped data I also get the markup I used to find the data.

    Here is my code

    PHP Code:
    $url "http://mysite.com";
    $raw file_get_contents($url);
    preg_match('/(<p class="content">.*<\/p>)/isU',$raw,$output);
    echo 
    $output[1]; 
    Ho can I make it when I echo the $output string it omits the <p class="content"> & </p>

    ?

    Thanks.

  2. #2
    Join Date
    Mar 2011
    Posts
    4
    PHP Code:
    $url "http://mysite.com"
    $raw file_get_contents($url); 
    preg_match('/<p class="content">(.*)<\/p>/isU',$raw,$output); 
    echo 
    $output[1]; 
    The parentheses specifies the data you want.

  3. #3
    Join Date
    Mar 2006
    Posts
    38
    Thanks. Works like a charm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles