note 35587 added to function.settype

From: Date: Sun, 07 Sep 2003 02:03:15 +0000
Subject: note 35587 added to function.settype
Groups: php.notes 
Request: Send a blank email to php-notes+get-55560@lists.php.net to get a copy of this message
Using settype is not the best way to convert a string into an integer, since it will strip the string wherever the first non-numeric character begins. The function intval($string) does the same thing. If you're looking for a security check, or to strip non-numeric characters (such as cleaning up phone numbers or ZIP codes), try this instead: <? $number=ereg_replace("[^0-9]","",$number); ?> ---- Manual Page -- http://www.php.net/manual/en/function.settype.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35587 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35587&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35587&report=yes

« previous php.notes (#55560) next »