SV: [PHP] converting str with \n to one line str??

From: Date: Tue, 21 Aug 2001 09:11:44 +0000
Subject: SV: [PHP] converting str with \n to one line str??
Groups: php.general 
Request: Send a blank email to php-general+get-63659@lists.php.net to get a copy of this message
Allmost, but you have to look for the \r ass well! With str_replace you can use an array as the search argument. Like this $arrReplace = array ("\n","\r"); $temp = str_replace($arrReplace,"",$temp); $temp = addcslashes($temp,"'"); // just to make sure that the string will work as my JS string thanks for the help :-) jens -----Oprindelig meddelelse----- Fra: David Robley [mailto:huntsman@www.nisu.flinders.edu.au] Sendt: 21. august 2001 09:43 Til: Jens Schødt Cc: 'php-general@lists.php.net' Emne: Re: [PHP] converting str with \n to one line str?? On Tue, 21 Aug 2001 16:49, Jens Schodt wrote: > $temp = str_replace("\n","test",$temp) is doing the same thing. It is > still a string in several lines if you look in the source :-( > > jens > > -----Oprindelig meddelelse----- > Fra: Tyler Longren [mailto:tyler@captainjack.com] > Sendt: 20. august 2001 20:20 > Til: Jens > Cc: php-general@lists.php.net > Emne: Re: [PHP] converting str with \n to one line str?? > > > You could use str_replace(). > > -- > Tyler Longren > Captain Jack Communications > tyler@captainjack.com > www.captainjack.com > > > > On Mon, 20 Aug 2001 20:15:54 +0200 > > "Jens" <nice@email.dk> wrote: > > When I use Javascript with PHP i run into one problem. When I get the > > data i > > need from the database it often has a lot of <br> and \n (new lines) > > in it. > > The <br> are no problem when converting a string to a Javascript > > string, but > > the \n are. The string has to be all in one line. > > > > example: > > <? $temp = "here > > I > > am"; ?> > > > > <script>var temp = <? echo $temp?> </script> > > > > This is not working!! But this would : > > > > <? $temp = "here I am"; ?> > > > > <script>var temp = '<? echo $temp?>'; </script> > > > > Can you help me please? > > > > thanks Jens Regular expressions? There is an example for ereg_replace in the manual that does just this: $string = ereg_replace ("\n", "", $string); /* Get rid of any newline characters in $string. */ -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA "Yes, I have been reading Voltaire," Tom admitted candidly.

« previous php.general (#63659) next »