Problem with ctype_alnum and spanish characters

Discussion in 'Programming/Scripts' started by danf.1979, Mar 25, 2006.

  1. danf.1979

    danf.1979 ISPConfig Developer

    I have this on my source code, but it does not work:
    PHP:
    setlocale(LC_ALL'es_CL.utf8');

    // Do add result
    $clean = array();
    if (isset(
    $_POST["name"]) && !empty($_POST["name"]) && ctype_alnum($_POST["name"]) && strlen($_POST["name"]) < 50) {
            
    $mysql["name"] = clean_input($_POST["name"]);
    }
    And the locale is there:
    Code:
    dan@www:~$ locale -a | grep CL
    es_CL.utf8
    
    I want ctype_alnum to recognize characters like á,ó,ú, etc... is this possible? someone has done it?
    Thanks.
     
  2. danf.1979

    danf.1979 ISPConfig Developer

    This is an alternative solution:

    PHP:
    // _ctype_alnum accepting spanish chars
    function _ctype_alnum($string)
    {
        
    $convert = array(
                        
    "á"=>"a""é"=>"e""í"=>"i""ó"=>"o""ú"=>"u""ñ"=>"n",
                        
    "Á"=>"A""É"=>"E""Í"=>"I""Ó"=>"O""Ú"=>"U""Ñ"=>"N"
                        
    );
        
    $string strtr($string$convert);
        return 
    ctype_alnum($string);
    }
     
    Last edited: Apr 18, 2006

Share This Page