[solution] Removing newlines in your output

By.

min read

My profile

Share this:

A newline is mostly a n but could also be a rn ..

So if you need to have a result from your database and you NEED to have that string on 1 single line ( because of a javascript tool that needs a string on 1 single line … ) act like this:

[code:1:f71be4687d] while ($row = mysql_fetch_array($result)) {
if($removenewlines)
{
$row[’text’] = str_replace(“rn”,’ ‘,$row[’text’]);
}
}[/code:1:f71be4687d]

Which would look functionwhise something like this :
[code:1:f71be4687d]/**
* Clears strings from their newlines, handy if you need a string in javascript ..
* @author Ramon Fincken
* http://www.ramonfincken.com/permalink/topic88.html
*/
function remove_newlines($txt)
{
$txt = str_replace(“rn”,’ ‘,$txt);
return $txt;
}[/code:1:f71be4687d]

Instead of rn a n could also do the trick.
Optional in the replace is a <br/> 🙂

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *