Thursday, September 27, 2018

php - Get contents of a div from a URL











I need to crawl through a page and get the contents of a particular div. I have php and javascript as my two main options. How can it be done?


Answer



This is quite a basic method to do it PHP and it returns the content in plain text. However you might consider revising the regex for your particular need.



  $link = file_get_contents("http://www.domain.com");

$file = strip_tags($link, "
");
preg_match_all("/
(?:[^<]*)<\/div>/is", $file, $content);
print_r($content);
?>

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...