[SOLVED] Separating text from numbers in a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

[SOLVED] Separating text from numbers in a string

Post by michlcamp »

Because of the nature of a UPS shipping script installed on my site, the value passed from a selected checkbox field in the script is both text and numeric - ex: UPS Ground=11.44

Is there a way to parse the text away from the number so that I could end up with two fields :

$ship_type="UPS Ground"
$shipping="11.44"

?
Any help much appreciated.
thanks in advance.
mc
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

$myString = 'UPS Ground=11.44';
$new_array = explode("=", $myString );
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post by michlcamp »

right, but still doesn't show me how to assign the exploded values to the two fields...
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Code: Select all

$myString = 'UPS Ground=11.44';
$new_array = explode("=", $myString ); 

$ship_type = $new_array[0];
$shipping = $new_array[1];
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post by michlcamp »

perfect! tanksmuch
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Moved to PHP Code ;)
Post Reply