hi ...
i know the function nl2br
but i want all the \n to be removed from a text in a variable... how do i do that ?
thanks ...
| SitePoint Sponsor |
hi ...
i know the function nl2br
but i want all the \n to be removed from a text in a variable... how do i do that ?
thanks ...





hows about :
Matt.PHP Code:<?php
$foo = str_replace( "\n", "", $bar ) ;
?>![]()
not working
it comes with line-breaks ...





Which method? The one firepages posted doesn't work because he used single quotes.
(I saw it mate, don't think you can delete it and hide.![]()
)
The method I posted does work cos I tried it;
Matt.PHP Code:<?php
$bar = "Hello, this is a \ntwo line string" ;
$foo = str_replace( "\n", "", $bar ) ;
echo "<pre>" ;
print_r( $foo ) ;
echo "</pre>" ;
?>![]()
i actually want to put the $var in a javascript and it needds to be in one line but str_replace doesn't remove the line-breaks ...
e.g.
$var1 = "Hi
there
how are you ";
So when i output in html it shud come:
hi there how are you





You must be using an editor set for win32 line breaks. Try this:
*note the space in the replace field.PHP Code:<?php
$foo = str_replace( "\r\n", " ", $bar ) ;
?>
Matt.![]()
gr8 this works ... thanx





lol Mincer - I deleted mine cos I saw yours and thought whats the point as I thought they were the same (I started my post 1/2 an hour before I actually pressed submit (no it didnt take me that long to work it out))
And if I used single quotes then you are right it would not have worked ! - but hey it was only in existance for a few minutes![]()
Bookmarks