note 68397 added to language.types.string

From: Date: Tue, 25 Jul 2006 15:39:57 +0000
Subject: note 68397 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-115163@lists.php.net to get a copy of this message
The simplest way to convert a string value to a number is to use $string+0 $string='a'; if ($string+0===0) echo 'true'; if $string is not a valid number it will return "0" (which is a number) The most useful use of this trick is to make sure you are using integer in sql queries like $query='DELETE FROM table WHERE id='.($_GET['id']+0); You could be pretty sure someone will not hack your script by SQL injection. ---- Server IP: 217.75.128.29 Probable Submitter: 83.228.60.26 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- http://master.php.net/note/edit/68397 Del: integrated -- http://master.php.net/note/delete/68397/integrated Del: useless -- http://master.php.net/note/delete/68397/useless Del: bad code -- http://master.php.net/note/delete/68397/bad+code Del: spam -- http://master.php.net/note/delete/68397/spam Del: non-english -- http://master.php.net/note/delete/68397/non-english Del: in docs -- http://master.php.net/note/delete/68397/in+docs Del: other reasons-- http://master.php.net/note/delete/68397 Reject -- http://master.php.net/note/reject/68397 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115163) next »