note 121263 added to function.filter-var
| From: | divinity76 at gmail dot com | Date: | Thu, 22 Jun 2017 11:00:33 +0000 |
| Subject: | note 121263 added to function.filter-var | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209146@lists.php.net to get a copy of this message | ||
note that FILTER_VALIDATE_BOOLEAN tries to be smart, recognizing words like Yes, No, Off, On, both
string and native types of true and false, and is not case-sensitive when validating strings.
<?php
$vals=array('on','On','ON','off','Off','OFF','yes','Yes','YES',
'no','No','NO',0,1,'0','1','true',
'True','TRUE','false','False','FALSE',true,false,'foo','bar');
foreach($vals as $val){
echo var_export($val,true).': ';
var_dump(filter_var($val,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE));
}
?>
outputs:
'on': bool(true)
'On': bool(true)
'ON': bool(true)
'off': bool(false)
'Off': bool(false)
'OFF': bool(false)
'yes': bool(true)
'Yes': bool(true)
'YES': bool(true)
'no': bool(false)
'No': bool(false)
'NO': bool(false)
0: bool(false)
1: bool(true)
'0': bool(false)
'1': bool(true)
'true': bool(true)
'True': bool(true)
'TRUE': bool(true)
'false': bool(false)
'False': bool(false)
'FALSE': bool(false)
true: bool(true)
false: bool(false)
'foo': NULL
'bar': NULL
----
Server IP: 72.52.91.14
Probable Submitter: 88.91.161.58
----
Manual Page -- http://php.net/manual/en/function.filter-var.php
Edit -- https://master.php.net/note/edit/121263
Del: integrated -- https://master.php.net/note/delete/121263/integrated
Del: useless -- https://master.php.net/note/delete/121263/useless
Del: bad code -- https://master.php.net/note/delete/121263/bad+code
Del: spam -- https://master.php.net/note/delete/121263/spam
Del: non-english -- https://master.php.net/note/delete/121263/non-english
Del: in docs -- https://master.php.net/note/delete/121263/in+docs
Del: other reasons-- https://master.php.net/note/delete/121263
Reject -- https://master.php.net/note/reject/121263
Search -- https://master.php.net/manage/user-notes.php