php: remove <p>, </p>, <br> and <br /> from beginning and end of string
- by andufo
$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?