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?

Link to comment
Share on other sites

\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

Link to comment
Share on other sites

\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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.