Forum Moderators: coopster
$patterns = array('/\<p\>(.*)\<\/p\>/i','/\<br\/\>/i','/\<br \/\>/i','/\<br\>/');
$replace = array("$1\n","\n");
echo preg_replace($patterns,$replace,$str);
Any help would be much appreciated..
Thanks
it works with one line html but not with multi line html
i.e: <p>I am inside html tag</p>I am just string <br/>Another string
2. The 3rd element in your patterns array has whitespace which should be escaped like this \s and should be '/\<br\s\/\>/i'
3. To my knowledge there is no need to escape the "<" and ">" signs but if you escape them in current situation should not be a problem.
4. you might wish to try this format instead:
<p\b[^>]*>(.*?)</p>
If you want the dot in (.*) to include line breaks you'll have to add "s" to the regex flags after the second delimiter. If you deal with Unicode strings you'll have to include "U" flag as well. I'm not sure if you can use the global flag "g" in PHP preg_replace pattern string to create array of all occurrences and replace them with their replacement array counterpart string.
PS: In fact "u" is for Unicode and "U" is for Ungreedy (.*) and this is the official list of supported preg_replace regex modes:
[us3.php.net...]