Solved

Separating Delimited list with multiple delimiters

Posted on 2013-05-16
3
238 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
  • 2
3 Comments
 
LVL 108

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)
0
 
LVL 108

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to count occurrences of each item in an array.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now