Jump to content

How do I tell PHP to look for an LF end of line break?


scott.stephan

Recommended Posts

So I've got this code that looks for line breaks and if it finds them, it removes them by smashing together the two strings:

 

$add_check=explode(???,$address);
if($add_check[2]){
$address=$add_check[1]." ".$add_check[2];
}

 

The problem is that I don't know WHAT to tell it to look FOR. I know it's the LF line break, which is \010 or + or *, but none of those seem to work. What do I fill "???" in with to tell PHP to look for the LF break?

\r is a carriage return, \n is a new line

 

\r is used in windows applications along with \n, and on *nix you only need \n, if you remove the \r from the windows text you'll still have the same, line seperated text.

 

just seperate by \n

\r is a carriage return, \n is a new line

 

\r is used in windows applications along with \n, and on *nix you only need \n, if you remove the \r from the windows text you'll still have the same, line seperated text.

 

just seperate by \n

 

Right- But I'm not looking to SEPERATE. This file is specifically coming in with LF linebreaks and I need to find them and remove thm.

I use PHP_EOL

 

for example, with this code:

$text = "this is some text\r\nand this is another line";
echo $text . '<br />';
echo str_replace(PHP_EOL, ' ', $text);

 

If you look at the source code, you will see:

 

This is some text
and this is another line
This is some text and this is another line

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.