Jump to content

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

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.