Saturday, 5 May 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

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...