php: remove <p>, </p>, <br> and <br /> from beginning and end of string

Posted by andufo on Stack Overflow See other posts from Stack Overflow or by andufo
Published on 2010-06-11T22:07:45Z Indexed on 2010/06/11 22:12 UTC
Read the original article Hit count: 276

Filed under:
|
$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. Any ideas?

© Stack Overflow or respective owner

Related posts about php

Related posts about XHTML