NYCPHP Meetup

NYPHP.org

[nycphp-talk] string function

Rolan Yang rolan at omnistep.com
Thu Jul 3 11:41:46 EDT 2008


Dan Cech wrote:
> Urb LeJeune wrote:
>>> An unknown string,its format is:
>>> y="tnk81|98.8$|yuhj78t|32.6$|tris78y|459.78$|....."
>> ..
>
> 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


OR

$p=explode('|',$y);
while ($p) {
        echo array_shift($p).' '.array_shift($p)."\n";
}

Rolan





More information about the talk mailing list