preg_match and line breaks
Posted: Wed Feb 09, 2005 3:29 pm
Im not very familiar with regular expressions (i have never work with them).. so here we go.
I wanna match words between tags. like this
so I have tried this, but it dont match when line breaks appears within the text:
can you help me with this. How can i match the text between tags that have line breaks? (i want to fetch ALL the text between them)
I wanna match words between tags. like this
Code: Select all
<tag1> hello world </tag1>Code: Select all
<?php
$string = <<<END
<tag1>without linebrakes works ok!!!</tag1>
<tag2>After this a linebreak.
linebreak
linebreak
linebreak
didnt work!!!</tag2>
END;
preg_match('/<(tag1)>(.+?)<\/\1>/', $string, $match );
preg_match('/<(tag2)>(.+?)<\/\1>/', $string, $match2 );
echo '<pre>';
print_r($match);
print_r($match2); //no match!!!
echo '</pre>';
?>