Skip to content

Replace all spaces in HTML with   except in HTML tags using PHP

If you would like to replace all the spaces in an HTML string with   so that you can render it out to the browser but you also want to retain current spaces in HTML tags you can use the below method:

This will replace:
<span>1</span> 2        3

..to look like this:

<span>1</span> 2 3

See also  How to create a Nickname Generator in Python
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x