tokam tokam - 1 month ago 9
PHP Question

strip_tags() .... replace tags by space rather than deleting them

Do you know how to replace html tags with a space character using php?

If I display

strip_tags('<h1>Foo</h1>bar');


I get as result "foobar" but what I need to keep words separate is "foo bar".

Answer

Try this.

preg_replace('#<[^>]+>#', ' ', '<h1>Foo</h1>bar');