note 92937 added to function.intval

From: Date: Sat, 15 Aug 2009 12:47:28 +0000
Subject: note 92937 added to function.intval
Groups: php.notes 
Request: Send a blank email to php-notes+get-159511@lists.php.net to get a copy of this message
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 ---- Server IP: 64.71.164.2 Probable Submitter: 79.179.75.38 ---- Manual Page -- http://www.php.net/manual/en/function.intval.php Edit -- https://master.php.net/note/edit/92937 Del: integrated -- https://master.php.net/note/delete/92937/integrated Del: useless -- https://master.php.net/note/delete/92937/useless Del: bad code -- https://master.php.net/note/delete/92937/bad+code Del: spam -- https://master.php.net/note/delete/92937/spam Del: non-english -- https://master.php.net/note/delete/92937/non-english Del: in docs -- https://master.php.net/note/delete/92937/in+docs Del: other reasons-- https://master.php.net/note/delete/92937 Reject -- https://master.php.net/note/reject/92937 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159511) next »