Re: Ereg help
| From: | Erwin | Date: | Fri, 25 Oct 2002 14:41:40 +0000 |
| Subject: | Re: Ereg help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121431@lists.php.net to get a copy of this message | ||
> "William Glenn" <wglenn01@charter.net> 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