sanfly Posted February 16, 2007 Share Posted February 16, 2007 Hi, I have addresses stored in a mysql database in a text field, so they look like this Joe Bloggs 2345 Pleasant Road Auckland New Zealand However, I need to put these addresses into javascript, and javascript doesnt like things going over two lines. I want to remove the "hidden" carriage returns/new line codes that make it display over mulitple lines when I extract from the database, but I can seem to figure out how to do it. Have tried a million different permuations using str_replace. Can anyone suggest how they would do it? Quote Link to comment https://forums.phpfreaks.com/topic/38834-removing-hidden-n-or-r/ Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 $str = 'Joe Bloggs 2345 Pleasant Road Auckland New Zealand'; $search = array("\n\r","\n","\r"); $str = str_replace($search, "<br />", $str); Quote Link to comment https://forums.phpfreaks.com/topic/38834-removing-hidden-n-or-r/#findComment-186775 Share on other sites More sharing options...
The_Assistant Posted February 17, 2007 Share Posted February 17, 2007 $str = 'Joe Bloggs 2345 Pleasant Road Auckland New Zealand'; $str = nl2br($str); Quote Link to comment https://forums.phpfreaks.com/topic/38834-removing-hidden-n-or-r/#findComment-186846 Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 nl2br doesn't remove the newline characters in only inserts an html break before them.... Description string nl2br ( string $string ) Returns string with '<br />' inserted before all newlines. http://www.php.net/nl2br he needs them to be removed. Quote Link to comment https://forums.phpfreaks.com/topic/38834-removing-hidden-n-or-r/#findComment-186849 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.