scott.stephan Posted July 13, 2009 Share Posted July 13, 2009 I'm dealing with a bunch of programs that handle customer data. Usually customers enter their address Tom Smith [LF] 187 Street Road, Apt 2 [LF] But sometimes they kick in a line break and we end up with Tom Smith [LF] 187 Street Road, [LF] Apt 2 [LF] In that second example, that second LF is causing all kinds of holy hell with the order management system our warehouse uses. How can I find/replace unwanted line breaks in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/ Share on other sites More sharing options...
nbarone Posted July 13, 2009 Share Posted July 13, 2009 explode() at the breaks, and if $myExplode[2] is valid, $name = $myExplode[0] and $addr = $myExplode[1] . " " . $myExplode[2] Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/#findComment-874792 Share on other sites More sharing options...
scott.stephan Posted July 13, 2009 Author Share Posted July 13, 2009 So, basically $add_check=explode(\010,$address); if($add_check[2]){ $address=$add_check[1]." ".$add_check[2]; } ? That seems about right. Is it possible to use \010 as an ASCII representation of \LF ? My other problem is how to tell PHP to look for the line break- Do I use \lf or \010 or what? Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/#findComment-874809 Share on other sites More sharing options...
nbarone Posted July 13, 2009 Share Posted July 13, 2009 a line break is \n Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/#findComment-874837 Share on other sites More sharing options...
scott.stephan Posted July 13, 2009 Author Share Posted July 13, 2009 a line break is \n Right, but this SPECIFCALLY an LF linebreak- Do they just all fall under the purview of "\n"? Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/#findComment-874864 Share on other sites More sharing options...
scott.stephan Posted July 13, 2009 Author Share Posted July 13, 2009 \n actually just yanks the "n"s. Do I do '\n'? Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/#findComment-874869 Share on other sites More sharing options...
nbarone Posted July 14, 2009 Share Posted July 14, 2009 use double quotes here explode("\n",$string); input: John Doe 123 Apple St. Apt 2 <?php $expinput = explode("\n",$input); if(sizeof($expinput) > 2){ $name = $expinput[0]; $addr = $expinput[1] . " " . $expinput[2]; } else { $name = $expinput[0]; $addr = $expinput[1]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/165848-solved-finding-and-replacing-unwanted-linebreaks/#findComment-875118 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.