note 109750 deleted from function.intval by cmb

From: Date: Sun, 16 Feb 2020 13:53:05 +0000
Subject: note 109750 deleted from function.intval by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-214155@lists.php.net to get a copy of this message
Note Submitter: gregrobson at gmail dot com ---- I just wanted to be sure that a string was going to be valid if I intval'ed it. This regular expression matches: 0 Any positive integer (no + sign) Any negative integer (with a - sign) It does not match a leading 0 or any other character. You are advised to strip out commas, trim the string and check range yourself ;) <?php /** * Loops through each non-array element and actions a function. * * @return boolean|integer TRUE if the value matches as an integer, FALSE if * an error occured or 0 if not match was found. */ public function validate($value) { $value = preg_match('/^(0|(-{0,1}[1-9]\d*))$/', trim($value)); if ($value == 1) return true; else return $value; } ?> If you use intval() now, you are merely changing the data type.

« previous php.notes (#214155) next »