At 04:52 PM 2/2/2006, Keith Proctor wrote:
I need to add two numbers together, unfortunately one of them is a
string that starts with a character.  I'd like to convert a string
such as 'x5' to the number 5.


Keith,

You could chop characters off the front until you've got a numeric:

        while (!is_numeric($sString) && $sString > "")
        {
                $sString = substr($sString, 1);
        }

or you could delete all non-numeric characters wherever they appear:

        $sString = preg_replace("/[^\d\.\-]/", "", $sString);

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

Reply via email to