Do you mean you want to strip out all tags except img tags? Use this:
$str = preg_replace('#\[(?!/?img).+?]#im','',$str);
题
I have this array of possible values that I want to replace with preg_replace
function:
$attr = array('b','i','u','left','center','right');
foreach($attr as $a) {
// strip bbcode
$str = preg_replace('#\['.$a.'\](.*)\[/'.$a.'\]#im','$1',$str);
}
return $str;
but instead of using foreach and looping through each possible exclusion, I want to do it like strip anything that isn't an img
instead. Is this possible?
解决方案
Do you mean you want to strip out all tags except img tags? Use this:
$str = preg_replace('#\[(?!/?img).+?]#im','',$str);