Allowchar function not functing. So it's really not a function at the min.
Hey, i'm on a steep learning curve.
I have to be complete converted to PHP from ASP.NET in a week. I'm trying to convert some SQL Protector from ASP.NET to PHP Now this function doesn't seem to work.
I have loaded an array with allow chars then used ! which i had picked up as NOT.
So the strstr function should come back with the first charater that not in the allow array. Thats what i belive this script should be doing but it's not.
Can someone point me in the right directory? please
BTW no errors are displayed.
PHP Code:
<?
$allowchar = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "@", ".", "-", "_", "+");
if (strstr($checkuser,!$allowchar)) {
echo "there is some bad mojo in this string";
}
?>
Re: Allowchar function not functing. So it's really not a function at the min.
The strstr() function searches for one string inside another. You are giving it an array. If you want to make sure the string contains only a certain subset of characters then you'll need to examine each character individually. You can do this by using a loop and the substr() function:
PHP Code:
<?php
function check_string($str)
{
$allowed = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "@", ".", "-", "_", "+");
$len = strlen($str);
for($x = 0; $x < $len; $x++) {
if (! in_array(substr($str, $x, 1), $allowed)) {
return false;
}
}
return true;
}
?>
Re: Allowchar function not functing. So it's really not a function at the min.