Forum Moderators: coopster

Message Too Old, No Replies

Stripping 'new line' from html in php

         

turbohost

8:08 pm on Jan 11, 2005 (gmt 0)

10+ Year Member



Hi guys,

How can I strip new lines from html code? E.g. I've got a parameter $g which holds the value "

blabla

" and I want to strip all the new lines from this parameter. The value of this parameter was fetched from a html page.

Thx,
Turbo

StupidScript

8:16 pm on Jan 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To replace newlines with nothing:

On a Windows system, try:

$g = str_replace("\r\n","",$g);

On a Linux/Unix system try:

$g = str_replace("\n","",$g);

Or, to replace the newlines with the word "fudge" on a *Nix system:

$g = str_replace("\n","fudge",$g);

... I think you get my drift ... :)

turbohost

8:23 pm on Jan 11, 2005 (gmt 0)

10+ Year Member



Thx stupid :), I forgot the \r

jshpro2

8:54 pm on Jan 11, 2005 (gmt 0)

10+ Year Member



I'm not a mac expert but I remember reading somewhere that mac uses \r for a new line...

So I use this:

$data=str_replace("\r","",$data);
$data=str_replace("\n","",$data);