Opposite of nl2br? Is it str_replace?

Posted by Julian H. Lam on Stack Overflow See other posts from Stack Overflow or by Julian H. Lam
Published on 2010-03-22T18:28:28Z Indexed on 2010/03/22 18:31 UTC
Read the original article Hit count: 410

Filed under:
|

So the function nl2br is handy. Except in my web app, I want to do the opposite, interpret line breaks as new lines, since they will be echoed into a pre-filled form.

str_replace can take <br /> and replace it with whatever I want, but if I put in \n, it echoes literally a backslash and an n. It only works if I put a literal line break in the middle of my script, and break the indentation (so there are no trailing space).

See:

    <?=str_replace('<br />','
',$foo)?>

Am I missing escape characters? I think I tried every combination...

© Stack Overflow or respective owner

Related posts about html

Related posts about php