Re: Check valid chars in string
| From: | liljim | Date: | Mon, 02 Dec 2002 15:39:06 +0000 |
| Subject: | Re: Check valid chars in string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126721@lists.php.net to get a copy of this message | ||
It's missing a closing brace. I would, however, tend to drop that way of
doing things and use a regex:
function ValidChard($file_name)
{
if(preg_match("![^a-z0-9\-\.]!is", $file_name))
{
return false;
}
return true;
}
Much easier on the eye, don't you think? :)
James
"Magnus Nilsson" <magnus.nilsson@hyperisland.se> wrote in message
news:066B63AD-0608-11D7-88C3-000393AB34CC@hyperisland.se...
function valid_chars($file_name)
{
for($i = 0; $i < strlen($file_name); $i++)
{
if (!in_array($file_name[$i],
array('q','w','e','r','t','y','u','i','o','p','l','k','j','h',
'g','f','d','s','a','z','x','c','v','b','n','m','Q','W',
'E','R','T','Y','U','I','O','P','L','K','J','H','G','F',
'D','S','A','Z','X','C','V','B','N','M','0','1','2','3',
'4','5','6','7','8','9', '.',
'_')))
{
return false;
}
else
{
return true;
}
}
Found this snippet of code on php.net
(http://www.php.net/manual/sk/ref.strings.php), but it just reurns a
parse error.
OS: OS X 10.2
PHP: PHP 4.2.3
MYSQL: 3.23.51
// magnus n.