Page 1 of 1

[SOLVED] Separating text from numbers in a string

Posted: Tue Dec 20, 2005 10:35 am
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

Posted: Tue Dec 20, 2005 10:38 am
by hawleyjr

Code: Select all

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

Posted: Tue Dec 20, 2005 10:43 am
by michlcamp
right, but still doesn't show me how to assign the exploded values to the two fields...

Posted: Tue Dec 20, 2005 10:44 am
by hawleyjr

Code: Select all

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

$ship_type = $new_array[0];
$shipping = $new_array[1];

Posted: Tue Dec 20, 2005 11:05 am
by michlcamp
perfect! tanksmuch

Posted: Tue Dec 20, 2005 11:07 am
by Chris Corbyn
Moved to PHP Code ;)