Ustag Posted April 3, 2011 Share Posted April 3, 2011 Hi I have a text field that when people add it to my database text and linebreaks looks like this in the db: HinextnextWith nl2br() it looks like this:hi <br><br>next<br>next<br>What I need is this:hi<br><br>next<br>next<br>Does anybody know what I can use to reach this instad of with nl2br()? Link to comment Share on other sites More sharing options...
birbal Posted April 3, 2011 Share Posted April 3, 2011 both will do the same job.i am not sure though why you need that. Link to comment Share on other sites More sharing options...
Ustag Posted April 3, 2011 Author Share Posted April 3, 2011 I dont think you understand my question. Both what?I need everything in one line for my java script to work. Link to comment Share on other sites More sharing options...
birbal Posted April 3, 2011 Share Posted April 3, 2011 ohh...you need to use something like.. preg_replace("/[\n]/","",nl2br($content)); or str_replace("\n","",nl2br($content)); Link to comment Share on other sites More sharing options...
Fmdpa Posted April 3, 2011 Share Posted April 3, 2011 I'm not sure why you'd need it all on one line, but you should be able to remove line breaks with this regular expression:JS regex: /(\r\n|\n|\r)/gmPHP regex: '/(\r\n|\n|\r)/s'Example usage: var text = "Multiline text !"text.replace(/(\r\n|\n|\r)/gm, ''); Or PHP: $text = "Multiline text !";$text = preg_replace('/(\r\n|\n|\r)/s', ''); Link to comment Share on other sites More sharing options...
Ustag Posted April 3, 2011 Author Share Posted April 3, 2011 thanks guys Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.