Return to Snippet

Revision: 34655
at October 26, 2010 18:53 by carbonr


Initial Code
<?php 
// extract numbers from a string 

$string = "The 1. Quick and 2. Brown fox said 3. (!@*(#!@*"; 

$new_string = ereg_replace("[^0-9]", "", $string); 


echo $new_string; 
// output: 123
?>

Initial URL


Initial Description
Will help convert string to number  OR get number in a selected string.

Initial Title
Extract Numbers from a string

Initial Tags
php, number

Initial Language
PHP