tags:

views:

38

answers:

1

help...

$chars = " \t\n\r\0\x0B";
$pattern = '('.implode('|',array_map('preg_quote',array('<p>','</p>','<br />','<br>'))).')'."\b";
$data = trim(preg_replace('~'.$pattern.'$~i','',preg_replace('~^'.$pattern.'~i','',trim($data,$chars))),$chars);

That code is set to remove all <p>,</p>,<br> and <br /> from the beginning and end of a html string. But it is no working quite alright. Any ideas?

+2  A: 

Why not just use something like this:

$subpattern = '(<(br|p)[^>]*>)';

$pattern = '~(^'.$subpattern.'|'.$subpattern.'$)~i';

Then, all you need to do is:

$data = trim(preg_replace($pattern, '', $data), $chars);
ircmaxell
great! although, i had to modify the subpattern to: $subpattern = '(</?(br|p) ?/?[^>]*>)';
andufo