Search code examples
phpregexpreg-matchline-breaks

Regular expressions preg_match with line breaks


I'm trying to match a string inside an HTML

for example I want to find the string inside <strong> string </strong>

what I'm doing is

preg_match_all('|\<strong\>(.*)\<\/strong>|',$html,$data);

echo $data[1][0];

it works when the string I want to search inside <strong> is not a line break but if it has a line break, how can I do it?

not working example:

<strong>
line break string
</strong>

Solution

  • Use:

    preg_match_all('/<strong>(.*)<\/strong>/s',$html,$data);