obay Posted July 3, 2009 Share Posted July 3, 2009 I'm trying to replace new lines "\n" with "<br />"s but none of these seem to work: nl2br($text) str_replace("\n",'<br />',$text) oh, it adds the <br /> all right, but it still doesn't remove the \n. If text is the quick brown fox it is converted to the quick <br />brown fox when it's supposed to be the quick<br />brown fox I've tried everything else: ereg_replace, using "%0D%0A" instead of "\n", using "\n\r" instead of "\n".. etc. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/164618-solved-nl2br-or-str_replace-cannot-replace-new-lines-with/ Share on other sites More sharing options...
xtopolis Posted July 3, 2009 Share Posted July 3, 2009 Try str_replace("\\n",'<br />',$text); Link to comment https://forums.phpfreaks.com/topic/164618-solved-nl2br-or-str_replace-cannot-replace-new-lines-with/#findComment-868174 Share on other sites More sharing options...
obay Posted July 3, 2009 Author Share Posted July 3, 2009 Try str_replace("\\n",'<br />',$text); No it doesn't work. It replaces all "n"s with <br /> lol any other ideas? Link to comment https://forums.phpfreaks.com/topic/164618-solved-nl2br-or-str_replace-cannot-replace-new-lines-with/#findComment-868200 Share on other sites More sharing options...
obay Posted July 3, 2009 Author Share Posted July 3, 2009 SOLVED. $input=str_replace(array("\r\n", "\n"),"",nl2br(htmlentities($_POST["field"]))); Here: http://www.phpfreaks.com/forums/index.php?topic=249369.0 Link to comment https://forums.phpfreaks.com/topic/164618-solved-nl2br-or-str_replace-cannot-replace-new-lines-with/#findComment-868205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.