?
Solved

Separating Delimited list with multiple delimiters

Posted on 2013-05-16
3
Medium Priority
?
253 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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

770 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