Separating Delimited list with multiple delimiters

Posted on 2013-05-16
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 110

Accepted Solution

Ray Paseur earned 500 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 110

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Only run code if on a certain page 11 34
pass foreach data in php into jquery ajax 10 49
How Close unsubmited attempts 10 46
while read ID; do 4 56
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
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 …

749 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