validate non-ASCII characters

Discussion in 'PHP' started by brio, Feb 6, 2007.

  1. #1
    hey, i'm having a bit of trouble trying to find a function that can validate non-ASCII characters in PhP on a form (accents,é,í,ó,ú,ã,etc).
    Please help me, i'm lost!
     
    brio, Feb 6, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    What do you mean with "validate"?

    chr() might help.
     
    nico_swd, Feb 6, 2007 IP
  3. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #3
    I was waiting for someone to post, I'm not so sure about support for non-standard letters nor do I have any on my board, however aswell as chr, ord might be useful as it returns the asci value, possibly if ord can convert it to an asci digit then chr should be able to turn it back, and so you can loop through and validate the form input.....
     
    krakjoe, Feb 6, 2007 IP
  4. brio

    brio Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thx, tried the chr() for instance

    <pre>
    <?php
    foreach (range(1, 255) as $num) {
    $char = chr($num);
    $result = preg_match('/[^\x0-\x7F]/', $char);
    printf('%2d = %s => %d<br>', $num, $char, $result);
    }
    ?>
    </pre>

    seems ok?
     
    brio, Feb 6, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    well I get quite a lotta squares from that code, but can see the ones with accents on also, so be a bit more specific about how you want to validate the data, and we'll go from there ....
     
    krakjoe, Feb 6, 2007 IP