scott.stephan Posted July 13, 2009 Share Posted July 13, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/165853-how-do-i-tell-php-to-look-for-an-lf-end-of-line-break/ Share on other sites More sharing options...
RussellReal Posted July 13, 2009 Share Posted July 13, 2009 \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 Quote Link to comment https://forums.phpfreaks.com/topic/165853-how-do-i-tell-php-to-look-for-an-lf-end-of-line-break/#findComment-874842 Share on other sites More sharing options...
scott.stephan Posted July 13, 2009 Author Share Posted July 13, 2009 \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. Quote Link to comment https://forums.phpfreaks.com/topic/165853-how-do-i-tell-php-to-look-for-an-lf-end-of-line-break/#findComment-874863 Share on other sites More sharing options...
scott.stephan Posted July 13, 2009 Author Share Posted July 13, 2009 \n seemed to drop all my "n"s, can I use '\n'? Quote Link to comment https://forums.phpfreaks.com/topic/165853-how-do-i-tell-php-to-look-for-an-lf-end-of-line-break/#findComment-874870 Share on other sites More sharing options...
RussellReal Posted July 14, 2009 Share Posted July 14, 2009 you use "\n" not '\n' Quote Link to comment https://forums.phpfreaks.com/topic/165853-how-do-i-tell-php-to-look-for-an-lf-end-of-line-break/#findComment-874934 Share on other sites More sharing options...
haku Posted July 14, 2009 Share Posted July 14, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/165853-how-do-i-tell-php-to-look-for-an-lf-end-of-line-break/#findComment-874971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.