I was writing a regex match pattern, when I suddenly found out that preg_match_all isn't matching contents on a different line. What's up with that, and how do I fix it?
test1.php
$content = file_get_contents("test2.php");
preg_match_all("~startMatch(.+?)endMatch~", $content, $matches);
print_r($matches);
test2.php
startMatch text
endMatch
Results:
Array ( [0] => Array ( ) [1] => Array ( ) )
Expected Results:
Array ( [0] => Array ( [0] => startMatch text endMatch ) [1] => Array ( [0] => text ) )
However, we get the expected result, if startMatch text endMatch
is on the same line. What's up with that? Don't periods in regex match all characters? How do I fix it?