Results 1 to 3 of 3

Thread: Allowchar function not functing. So it's really not a function at the min.

  1. #1

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    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";
    }

    ?>
    Digitalmyth

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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$x1), $allowed)) {
                return 
    false;
            }
        }

        return 
    true;
    }
    ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Allowchar function not functing. So it's really not a function at the min.

    You want strspn() or strcspn().
    http://www.php.net/manual/en/function.strspn.php
    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
  •  



Click Here to Expand Forum to Full Width