Solved

Separating Delimited list with multiple delimiters

Posted on 2013-05-16
3
249 Views
Last Modified: 2013-05-16
Hi,

Can anyone explain why when I run the attached script I am getting a Rec_Num_30  followed by a Pos_Num_1 at the end? This seems to be some type or error but I cannot determine what's causing it.

Your help will be greatly appreciated.

ediinvoice1.php
0
Comment
Question by:Honya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39171956
You might want to remove the trailing tilde.
<?php // RAY_temp_honya.php
error_reporting(E_ALL);

$ediinvoice ="ST*810*8001~BIG*980226*INV123456*980131*PONUM-1234567~N1*SF**15*216793X~N1*ST**15*6678157~N1*BT**15*1135309~N1*VN**15*2002450~DTM*011*980226***19~IT1*1*16*UN*29*SR*IB*0835209881~CTP**SLP*29***DIS*.57~SAC*N~LM*BI*ACK~LQ**AC~IT1*2*32*UN*29.5*SR*IB*0835210020~CTP**SLP*29.5***DIS*.57~IT1*3*32*UN*26*SR*IB*0835210456~CTP**SLP*26***DIS*.57~IT1*4*48*UN*24*SR*IB*0835210979~CTP**SLP*24***DIS*.57~IT1*5*20*UN*6.99*SR*IB*0835211614~CTP**SLP*6.99***DIS*.57~IT1*6*40*UN*5.5*SR*IB*0835212653~CTP**SLP*5.5***DIS*.57~IT1*7*40*UN*6.99*SR*IB*0835209784~CTP**SLP*6.99***DIS*.57~IT1*8*20*UN*8.95*SR*IB*0835213153~CTP**SLP*8.95***DIS*.57~TDS*383750*383750*218736~CTT*8~SE*29*8001~";

// REMOVE THE EXTRANEOUS DELIMITER
$ediinvoice = rtrim($ediinvoice, '~');

$lines = explode("~", $ediinvoice);

$n = 0;
foreach ($lines as $edirecords)
{
    $n++;
    $p =0;
    $rec = '<span style="color:red";>Rec_Num_'.$n.':'.'</span>';
    echo $rec . " " . $edirecords . "<br/>";

    $line = explode("*", $edirecords);
    foreach ($line as $edirecord)
    {
        $p++;
        $pos = '<span style="color:green";>Pos_Num_'.$p.':'.'</span>';
        echo $pos . " " . $edirecord . "<br/>";
    }
echo "<hr/>";
}

Open in new window

0
 

Author Closing Comment

by:Honya
ID: 39172320
Hi Ray,

Thanks again. I really appreciate how you provide well commented examples.

As the Japanese will say Domou arigatou goziamasu (Thank you very much)
1
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39172416
Thanks for the points! ~Ray
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question