星期日, 7月 31, 2005

Simple language detect function(PHP)

Well, I have some extra time so I develop this code snippet.



<?php

function hw_delectlang() {

    if (
substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) == 'en'){


        
$lang = 'en'; //English

    
} elseif (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2) == 'zh'){


        if ((
substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],3,2) != 'cn') && (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],3,2) != 'sg')){


            
$lang = 'cht'; //Chinese Trad.

        
} else {

            
$lang = 'chs'; //Chinese Simp.

        
}

    } else {

        
$lang = 'en'; //Default is English


    
}

    return
$lang;

}

?>



Hope this works.

沒有留言: