[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Separating Delimited list with multiple delimiters

Posted on 2013-05-16
Medium Priority
Last Modified: 2013-05-16

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.

Question by:Honya
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
LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 39171956
You might want to remove the trailing tilde.
<?php // RAY_temp_honya.php

$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~";

$ediinvoice = rtrim($ediinvoice, '~');

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

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

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

Open in new window


Author Closing Comment

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)
LVL 111

Expert Comment

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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 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