Cleaning newlines

While taking some plain/rich text in a database to populate a javascript function, i used


body.insertHtml( '<?= str_replace("n\\ ","",$answers[text]) ;?>'

to get those blank spaces and end lines out of the string. But, In fact, they are still there. Le’s see the result:


body.insertHtml( 'Dear customer,

We are actually trying to fix those nuclear problems in our servers. Please wait until some genius in SitePoint get us the answer.' )

This way of coding between php and jscript gets me an error “UNEXPECTED TOKEN”, while this other option gets me no error message, and runs perfect:


body.insertHtml( 'Dear customer, We are actually trying to fix those nuclear problems in our servers. Please wait until some genius in SitePoint get us the answer.' )

It’s curious, because I am actually trying to implement a function to insert some text in a textarea, just as we are doing right now, when appending the "<?php> tags through a button in the RTE format bar.

Is there any way that I can get rid of those blank/line spaces?

You could use…


<?= str_replace(array("\
", "\\r"), null, $answers['text']); ?>