note 58054 added to function.isset
| From: | ifyouwantblood dot de at osu1 dot php dot net | Date: | Sat, 22 Oct 2005 16:35:23 +0000 |
| Subject: | note 58054 added to function.isset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97415@lists.php.net to get a copy of this message | ||
i worked on a calculator so the user-input could be zero -> couldn´t use !empty() cause it
returns FALSE on those. but i was also too lazy to write:
if(isset($_GET['var']) && $_GET['var']!='')
so i wrote this function:
function cuv($varname,$postget=1)
{
if($postget)
{
if(isset($_POST[$varname]) && $_POST[$varname]!='') return (bool) 1;
else return (bool) 0;
}
else
{
if(isset($_GET[$varname]) && $_GET[$varname]!='') return (bool) 1;
else return (bool) 0;
}
}
so to check GET vars i only have to write:
if(cuv($varname,0))
and for post vars only:
if(cuv($varname))
----
Manual Page -- http://www.php.net/manual/en/function.isset.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58054
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58054&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58054&report=yes
Search -- http://master.php.net/manage/user-notes.php