星期日, 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.

星期三, 6月 08, 2005

PHP & Java both have their 10 years old birthday in this month

Well, today is the PHP's 10 years old birthday! And Java will have its 10 years old birthday in this month too! As a PHP programmer, I think today is quite special and I should do something special today!