|
-
Feb 15th, 2005, 07:44 PM
#1
Thread Starter
Addicted Member
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";
}
?>
-
Feb 15th, 2005, 08:32 PM
#2
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;
}
?>
-
Feb 16th, 2005, 03:35 AM
#3
Re: Allowchar function not functing. So it's really not a function at the min.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|