NYCPHP Meetup

NYPHP.org

[nycphp-talk] string function

Dan Cech dcech at phpwerx.net
Thu Jul 3 10:45:15 EDT 2008


Urb LeJeune wrote:
>> 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";

You could write this a little more simply as:

$parts = explode('|',$y);
$cnt = count($parts);

for ($i = 0;$i < $cnt - 1;$i += 2) {
   echo $parts[$i] .' '. $parts[$i+1] ."<br/>\n";
}

Dan



More information about the talk mailing list