Jump to content

[SOLVED] preg_match logical error


plznty

Recommended Posts

<?php
$s = file_get_contents("page.html");
preg_match('/<div class="brown_box main_ge_page vertically_spaced"><div class="subsectionHeader">(.*)<\/div>/', $s, $m);
echo $m[1];
?>

 

page.html content

<div class="brown_box main_ge_page vertically_spaced">
<div class="subsectionHeader">
Works
</div>

 

How come it doesnt get the word, "Works".

Thank you

Link to comment
https://forums.phpfreaks.com/topic/180496-solved-preg_match-logical-error/
Share on other sites

Because there's a line break between the two divs. Try to add \s* between them, and you should also make your quantifier lazy by adding a question mark after .* (stopping the match at the first encountered </div> character sequence, not the last).

  • 2 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.