> "William Glenn" <[EMAIL PROTECTED]> wrote in message
news:003101c27c3b$ff8c61a0$6401a8c0@;cortez.co.charter.net...
> Hey all,
> I've been fighting this all night, I need a bit of help. I have a string
like.
>
> #21-935 Item Description: $35.95
>
> Where the part # could be 10-2034 a combination of 2 and 3 or 4 digits,
and the price could be a combination of 1,2,3 . 2 digits. I want to chop
that string into Part # / Description / Price.
>
> I'd appreciate any help, I know this is probably real simple :) Thanks in
advance.

Try:

<?
$item = '#21-935 Item Description: $35.95';
$all = explode( ' ', $item );
$part_nr = substr( array_shift( $all ), 1 );
$rest = explode( '$', implode( ' ', $all ) );
$description = substr( trim( $rest[0] ), 0, -1 );
$price = $rest[1];
?>

I bet there is a much nicer (and maybe faster way), but this is by far the
easiest (it doesn't cost one night) ;-))
One hundred thousand of these iterations took about 2 seconds...

Grtz Erwin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to