Jump to content

[SOLVED] Finding and Replacing unwanted linebreaks?


scott.stephan

Recommended Posts

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?

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?

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];
}
?>

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.