Ok I need to replace spaces in a textarea with like . When its saved and then displayed on a page, the beginning spaces before a line disappear, but are still there when u edit the text again in a textarea. So I figure if the spaces are replaced with an nbsp then they will always show when they should? I've tried using $minutes = preg_replace('/ /', ' ', $minutes); and it replaced spaces with <br />. So anyone got a plan?
$minutes = str_replace(" ", "&nbsp;", $minutes);
and then before you go to edit the textarea
$minutes = str_replace("&nbsp;", " ", $minutes);
you may also be interested in [man]nl2br[/man]
Actually my way worked, but I noticed I had it after it changed all \n to <br /> which made it make the space inside the <br /> an ! Hah. Thanks anyways! _
Use drew010's method instead.
If regular expression search and replace can be feasibly be avoided, then avoid it.
str_replace() is faster than preg_replace().
Ok thanks! 🙂