With preg_replace in PHP, I am trying to match a regex pattern multiple times in a string, sometimes there will be 2 matches on 1 lines, sometimes not.
I have the following string:
 $text = 'Check <a href="link1">text1</a> or <a href="link2">text2</a>
 oh
 well <a href="link3">text3</a>';
I would like it to convert to:
 Check
 text1
 link1
 or
 text2
 link2
 oh
 well
 text3
 link3
I have this:
 $text = preg_replace('/(<a href=")(.+)(">)(.*)(<\/a>)/', "\n$4\n$2\n", $text);
But it doesn't work, only when having 1 match at a line. Like:
 $text = 'Check <a href="link1">text1</a> 
 or <a href="link2">text2</a>
 oh
 well <a href="link3">text3</a>'; 
Any help appreciated.
Example with a and b http://www.phpliveregex.com/p/4fU
 
     
    