Jeremysr Posted December 23, 2006 Share Posted December 23, 2006 I'm making a program where someone enters text into a textbox and then in the next page I need to change all the double newlines ("\n\n") into two linebreak tags. For some reason this works:[code]str_replace("\n", "<br />", $input);[/code]But this doesn't work:[code]str_replace("\n\n", "<br /><br />", $input);[/code]I want the single newlines to be ignored though. Can someone tell me what the problem is? Link to comment https://forums.phpfreaks.com/topic/31709-detecting-two-newlines/ Share on other sites More sharing options...
Orio Posted December 23, 2006 Share Posted December 23, 2006 Use [url=http://www.php.net/manual/en/function.nl2br.php]nl2br()[/url].The reason this doesn't work is because there's also the carriage return char. This would probbly work:[code]str_replace("\r\n", "<br />", $input);[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31709-detecting-two-newlines/#findComment-146962 Share on other sites More sharing options...
Jeremysr Posted December 23, 2006 Author Share Posted December 23, 2006 Ok thanks. I couldn't use nl2br() because it changes all of the newlines to br tags but I only want to change double newlines, not all of them. I'll try "\r\n\r\n". Link to comment https://forums.phpfreaks.com/topic/31709-detecting-two-newlines/#findComment-146963 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.