note 92937 deleted from function.intval by danbrown

From: Date: Sat, 15 Aug 2009 17:59:57 +0000
Subject: note 92937 deleted from function.intval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159519@lists.php.net to get a copy of this message
Note Submitter: lwc ---- Here's an easier solution for what michiel ed thalent nl gave: function str2int($string) { return preg_replace('/\D*(\d+(\.\d+)?)/', "$1", $string); } $str = "foobar123"; echo str2int($str); // "123" $str = "4foobar23"; echo str2int($str); // "423" // Sorry, this doesn't allow to give just 4 like michiel allowed

« previous php.notes (#159519) next »