Page 1 of 1

Getting number from string

Posted: Mon Apr 16, 2007 2:13 am
by winsonlee

Code: Select all

$string = ''RD0394D";
How can I extract the number out from the string ?

Posted: Mon Apr 16, 2007 2:54 am
by Christopher
You could try just casting it to an integer:

Code: Select all

$string = (int)"RD0394D";
// or use the function
$string = intval("RD0394D");
You could use a regular expression to remove all characters that are not numbers:

Code: Select all

$string = ''RD0394D";
$number = preg_replace('/[^0-9]/', '', $string);