Do you know how to replace html tags with a space character using php?
If I display
strip_tags(\'Foo
bar\');
Preg replace is fine most of the cases, there is that one corner case, as discussed here. This should work for both:
strip_tags(str_replace('<', ' <', $str));
Adding a space before any tag is valid in HTML. It too has some caveats like if your text has "<" for some reason and don't want to add space before it.
$string = '<h1>Foo</h1>bar';
$spaceString = str_replace( '<', ' <',$string );
$doubleSpace = strip_tags( $spaceString );
$singleSpace = str_replace( ' ', ' ', $doubleSpace );
try this:
$str = '<h1>Foo</h1>bar';
echo trim(preg_replace('/<[^>]*>/', ' ', $str));
First do a str_replace
$string = '<h1>Foo</h1>bar'
strip_tags(str_replace('</h1>', ' ',$string));