NYCPHP Meetup

NYPHP.org

[nycphp-talk] string function

Ken Robinson kenrbnsn at rbnsn.com
Thu Jul 3 11:01:36 EDT 2008


Quoting Urb LeJeune <urb at e-government.com>:

>
>> An unknown string,its format is:
>> y="tnk81|98.8$|yuhj78t|32.6$|tris78y|459.78$|....."
>
> list($Parts) = explode("|",$y);
> $Count = count($Parts);
> for($Sub1=0,$Sub2=1;$Sub2<=$Count;$Sub1++,$Sub1++,$Sub2++,$Sub2++)
>   echo "<br />$Parts[$Sub1] $Parts[Sub2]\n";
>

This works (tested)

<?php
$y="tnk81|98.8$|yuhj78t|32.6$|tris78y|459.78$";
$Parts = explode("|",$y);
$Count = count($Parts);
for($Sub1=0;$Sub1<=$Count;$Sub1 += 2) {
   $i = $Sub1 + 1;
   echo "<br />$Parts[$Sub1] $Parts[$i]\n";
   }
?>


Ken Robinson




More information about the talk mailing list