0

I want to get the data from a website, therefore I created the code below in php. The content which I want to get is inside a <div>:

<div class="post-text" itemprop="text">
    // Content I want to get 
</div>

My PHP code is as follow:

 <?php
    $page = file_get_contents('http://somewebsite.com');

    preg_match_all("/<div class=\"post-text\" itemprop=\"text\".*div>/", $page, $agent_name);

    print_r($agent_name);
?>

But when I execute the code, it does not show anything on the page. The output I get is like:

Array ( [0] => Array ( ) )

Can someone tell me what I am doing wrong?

Kevin
  • 874
  • 3
  • 16
  • 34

1 Answers1

0

For matching multiple lines of text, i usually use the PCRE_DOTALL modifier - using the pattern "/<div class=\"post-text\" itemprop=\"text\".*div>/s" instead of "/<div class=\"post-text\" itemprop=\"text\".*div>/" (just add the s at the end of your pattern) should give you the expected result.

Ste Bächler
  • 478
  • 3
  • 10