Convert space to non-breaking space

#1
[eluser]theprodigy[/eluser]
I need a good way to convert spaces to non-breaking spaces, but without screwing up html tags.

Example:
How would I convert
Code:
$string = '<p style="margin:0; color:#CCCCCC">This is a paragraph<p>';
into
Code:
$string = '<p style="margin:0; color:#CCCCCC">This&nbsp;is&nbsp;a&nbsp;paragraph<p>';

I know this is a bad example as you would never do that with a paragraph, but it's just an example.
I want to change all the spaces of text into non-breaking spaces, but leaving inside the tags as normal, so as not to screw up the html.

Is it just a matter of preg_replace, or is there an easier way?


Messages In This Thread
Convert space to non-breaking space - by El Forum - 05-03-2010, 11:31 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.