1.

Solve : PHP does not replace \n's?

Answer»

$stuff = file_get_contents($a);
$stuff = str_replace("'", "\'", $stuff);
$stuff = str_replace("\n", "", $stuff);
$stuff = str_replace("\n", "", $stuff);
$stuff = str_replace("\n", "", $stuff);


That is not removing the new lines. It still returns Code: [Select]<p align="center"><font SIZE="7">Bailey's Test Site</font></p>

<p align="center"><font face="verdana" size="5"><font face="courier new" size="4">Welcome to my website. I am currently the only</font></font></p>

<p align="center"><font face="Courier New" size="4">developer of HerbertsWorld. You cannot help. Sorry!</font></p>This of any help?Depending on O/S, "\n" is not the only component of a newline.  Remember that "\r" may also appear.  You want:

Code: [Select]$stuff = str_replace(array("\r", "\n"), '', $stuff); Dear Rob,

Thanks for your help. It really helped alot. I never knew \r was a javascript newline character.

Thanks! Quote from: Bannana97 on June 10, 2009, 12:41:22 PM

I never knew \r was a javascript newline character.

PHP character? I think...But it works in javascript.. Ok, just forget about this. lets say it's both :O*sigh* 

In Windows/DOS world, newlines are traditionally composed of a character return "character" (ASCII 13) followed by a line feed "character" (ASCII 10).  In Unix/Linux/Mac, a newline is traditionally composed of just a line feed.   This is therefore OPERATING system dependent, not programming LANGUAGE dependent.Thank you. and to further confuse things, Mac OS 9 and earlier I believe use just a carriage return!So for that I'd do this?



$? = str_replace("
", "", $?);

No, the example I gave you before covers all eventualities.


Discussion

No Comment Found