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

2001-08-21 Thread Jens Schødt

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:[EMAIL PROTECTED]]
Sendt: 21. august 2001 09:43
Til: Jens Schødt
Cc: '[EMAIL PROTECTED]'
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:[EMAIL PROTECTED]]
> Sendt: 20. august 2001 20:20
> Til: Jens
> Cc: [EMAIL PROTECTED]
> Emne: Re: [PHP] converting str with \n to one line str??
>
>
> You could use str_replace().
>
> --
> Tyler Longren
> Captain Jack Communications
> [EMAIL PROTECTED]
> www.captainjack.com
>
>
>
> On Mon, 20 Aug 2001 20:15:54 +0200
>
> "Jens" <[EMAIL PROTECTED]> 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  and \n (new lines)
> > in it.
> > The  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:
> >  > I
> > am"; ?>
> >
> > var temp =  
> >
> > This is not working!! But this would :
> >
> > 
> >
> > var temp = ''; 
> >
> > 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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-08-21 Thread Jens Schødt

Yes!! This was the solution...
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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sendt: 21. august 2001 09:31
Til: Jens Schødt; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Emne: RE: [PHP] converting str with \n to one line str??


just a thought - \r\n?

try stripping out \r's as well.  windows does \r\n  (carriage return, line
feed) for text, unix only \n's



-Original Message-
From: Jens Schodt [mailto:[EMAIL PROTECTED]]
Sent: August 21, 2001 3:20 PM
To: 'Tyler Longren'
Cc: '[EMAIL PROTECTED]'
Subject: SV: [PHP] converting str with \n to one line str??



$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:[EMAIL PROTECTED]]
Sendt: 20. august 2001 20:20
Til: Jens
Cc: [EMAIL PROTECTED]
Emne: Re: [PHP] converting str with \n to one line str??


You could use str_replace().

--
Tyler Longren
Captain Jack Communications
[EMAIL PROTECTED]
www.captainjack.com



On Mon, 20 Aug 2001 20:15:54 +0200
"Jens" <[EMAIL PROTECTED]> 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  and \n (new lines) in
> it.
> The  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:
>  I
> am"; ?>
> 
> var temp = <? echo $temp?> 
> 
> This is not working!! But this would :
> 
> 
> 
> var temp = '<? echo $temp?>'; 
> 
> Can you help me please?
> 
> thanks Jens
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-08-21 Thread Jens Schodt


$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:[EMAIL PROTECTED]]
Sendt: 20. august 2001 20:20
Til: Jens
Cc: [EMAIL PROTECTED]
Emne: Re: [PHP] converting str with \n to one line str??


You could use str_replace().

--
Tyler Longren
Captain Jack Communications
[EMAIL PROTECTED]
www.captainjack.com



On Mon, 20 Aug 2001 20:15:54 +0200
"Jens" <[EMAIL PROTECTED]> 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  and \n (new lines) in
> it.
> The  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:
>  I
> am"; ?>
> 
> var temp =  
> 
> This is not working!! But this would :
> 
> 
> 
> var temp = ''; 
> 
> Can you help me please?
> 
> thanks Jens
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




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

2001-08-21 Thread Jens Schodt

nl2br is not working in this case. It does put a  with every new line,
but it does not remove the new line. The string will still have the line
changes and it will not work in Javascript.


Jens

-Oprindelig meddelelse-
Fra: Artwithin [mailto:[EMAIL PROTECTED]]
Sendt: 20. august 2001 20:09
Til: Jens
Cc: [EMAIL PROTECTED]
Emne: Re: [PHP] converting str with \n to one line str??


use nl2br()
http://www.php.net/nl2br

or, alternatively, use a regex to strip out the newlines

hope this helps.

- Original Message -
From: Jens <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 20, 2001 11:15
Subject: [PHP] converting str with \n to one line str??


> 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  and \n (new lines) in
it.
> The  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:
>  I
> am"; ?>
>
> var temp =  
>
> This is not working!! But this would :
>
> 
>
> var temp = ''; 
>
> Can you help me please?
>
> thanks Jens
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]