ÍêÃÀ½â¾öPHPÖÐÎÄÂÒÂëÎÊÌâ
Ò».Ê×ÏÈÊÇPHPÍøÒ³µÄ±àÂë
¡¡¡¡1.phpÎļþ±¾ÉíµÄ±àÂëÓëÍøÒ³µÄ±àÂëӦƥÅä
¡¡¡¡a.Èç¹ûÓûʹÓÃgb2312±àÂ룬ÄÇôphpÒªÊä³öÍ·£ºheader(“Content-Type: text/html; charset=gb2312")£¬¾²Ì¬Ò³ÃæÌí¼Ó£¬ËùÓÐÎļþµÄ±àÂë¸ñʽΪANSI£¬¿ÉÓüÇʱ¾´ò¿ª£¬Áí´æÎªÑ¡Ôñ±àÂëΪANSI£¬¸²¸ÇÔ´Îļþ¡£
¡¡¡¡b.Èç¹ûÓûʹÓÃutf-8±àÂ룬ÄÇôphpÒªÊä³öÍ·£ºheader(“Content-Type: text/html; charset=utf-8")£¬¾²Ì¬Ò³ÃæÌí¼Ó£¬ËùÓÐÎļþµÄ±àÂë¸ñʽΪutf-8¡£±£´æÎªutf-8¿ÉÄÜ»áÓеãÂé·³£¬Ò»°ãutf-8Îļþ¿ªÍ·»áÓÐBOM£¬Èç¹ûʹÓà session¾Í»á³öÎÊÌ⣬¿ÉÓÃeditplusÀ´±£´æ£¬ÔÚeditplusÖУ¬¹¤¾ß->²ÎÊýÑ¡Ôñ->Îļþ->UTF-8Ç©Ãû£¬Ñ¡Ôñ×ÜÊÇɾ³ý£¬ÔÙ±£´æ¾Í¿ÉÒÔÈ¥µôBOMÐÅÏ¢ÁË¡£
¡¡¡¡2.php±¾Éí²»ÊÇUnicodeµÄ£¬ËùÓÐsubstrÖ®ÀàµÄº¯ÊýµÃ¸Ä³Émb_substr(ÐèҪװmbstringÀ©Õ¹);»òÕßÓÃiconvתÂë¡£
¡¡¡¡¶þ.PHPÓëMysqlµÄÊý¾Ý½»»¥
¡¡¡¡PHPÓëÊý¾Ý¿âµÄ±àÂëÓ¦Ò»ÖÂ
¡¡¡¡1.ÐÞ¸ÄmysqlÅäÖÃÎļþmy.ini»òmy.cnf£¬mysql×îºÃÓÃutf8±àÂë
¡¡¡¡[mysql]
¡¡¡¡default-character-set=utf8
¡¡¡¡[mysqld]
¡¡¡¡default-character-set=utf8
¡¡¡¡default-storage-engine=MyISAM
¡¡¡¡ÔÚ[mysqld]ϼÓÈë:
¡¡¡¡default-collation=utf8_bin
¡¡¡¡init_connect='SET NAMES utf8'
¡¡¡¡2.ÔÚÐèÒª×öÊý¾Ý¿â²Ù×÷µÄphp³ÌÐòǰ¼Ómysql_query("set names '±àÂë'");£¬±àÂëºÍphp±àÂëÒ»Ö£¬Èç¹ûphp±àÂëÊÇgb2312ÄÇmysql±àÂë¾ÍÊÇgb2312£¬Èç¹ûÊÇutf-8ÄÇmysql±àÂë¾ÍÊÇ utf8£¬ÕâÑù²åÈë»ò¼ìË÷Êý¾Ýʱ¾Í²»»á³öÏÖÂÒÂëÁË
¡¡¡¡Èý.PHPÓë²Ù×÷ϵͳÏà¹Ø
¡¡¡¡WindowsºÍLinuxµÄ±àÂëÊDz»Ò»ÑùµÄ£¬ÔÚWindows»·¾³Ï£¬µ÷ÓÃPHPµÄº¯Êýʱ²ÎÊýÈç¹ûÊÇutf-8±àÂë»á³öÏÖ´íÎ󣬱ÈÈç move_uploaded_file()¡¢filesize()¡¢readfile()µÈ£¬ÕâЩº¯ÊýÔÚ´¦ÀíÉÏ´«¡¢ÏÂÔØÊ±¾³£»áÓõ½£¬µ÷ÓÃʱ¿ÉÄÜ»á³öÏÖÏÂÃæµÄ´íÎó:
¡¡¡¡Warning: move_uploaded_file()[function.move-uploaded-file]:failed to open stream: Invalid argument in ...
¡¡¡¡Warning: move_uploaded_file()[function.move-uploaded-file]:Unable to move '' to '' in ...
¡¡¡¡Warning: filesize() [function.filesize]: stat failed for ... in ...
¡¡¡¡Warning: readfile() [function.readfile]: failed to open stream: Invalid argument in ..
¡¡¡¡ÔÚLinux»·¾³ÏÂÓÃgb2312±àÂëËäÈ»²»»á³öÏÖÕâЩ´íÎ󣬵«±£´æºóµÄÎļþÃû³öÏÖÂÒÂëµ¼ÖÂÎÞ·¨¶ÁÈ¡Îļþ£¬Õâʱ¿ÉÏȽ«²ÎÊýת»»³É²Ù×÷ϵͳʶ±ðµÄ±àÂ룬±àÂëת»»¿
Ïà¹ØÎĵµ£º
ÏÈÎÒÃÇÁ˽âÒ»ÏÂÎÒÃǵÄphp³ÌÐòÊÇÔõÑùÖ´Ðеģ¬Ê×ÏÈËû±»±àÒëΪÖмä´úÂ룬ȻºóÖмä´úÂë±»ËÍÈëÖ´ÐÐÒýÇæÖ´ÐУ¬È»ºóÏú»Ù¡£Ã¿¸öÇëÇóµÄÖмä´úÂëÔÚÖ´ÐÐÍêÖ®ºó±»Ïú»Ù£¬ÕâÑùµÄºÃ´¦ÔÚÓÚËûÍêÈ«¸ôÀëÁ˲»Í¬µÄÇëÇó£¬Ê¹ÄÚ´æÊ¹ÓÃÂʽµµÍ¡£µ«ÊÇÕâÑùµÄȱµãÒ²ÏÔ¶øÒ×¼û£¬ÒòΪËûÐèÒªÔÙÖØ¸´ÇëÇóÒ»¸ö½çÃæµÄʱºò¶ÔÒ»¸ö´úÂëÁ¬Ðø±àÒëÁ½´Î£¬±àÒëµÄÖмä´úÂëà ......
PHPÖеÄstristr()£¬strstr()£¬strpos()ËٶȱȽÏ
²âËÙ´úÂë:
<?php
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
......
½ñÌ칤×÷ÖÐÓöµ½ÁËPOSTÊý¾ÝµÄÎÊÌ⣬ÐèÒªÏòÒ»¸öÌØ¶¨µÄURL·¢ËÍPOSTÊý¾Ý¡£
ÏÖ½«PHP·¢ËÍPOSTÊý¾ÝµÄ·½Ê½×ܽáÏ£¬·½±ã×Ô¼ºÔ츣ºóÈË£º
·½·¨Ò»£ºHTTPº¯Êý·¢ËÍ·½Ê½
˵Ã÷£º$dataΪPOST·¢Ë͵ÄÊý¾Ý£º$keyΪ²ÎÊýÃû£¬$valΪ²ÎÊýÖµ
$URL = "http://pre.payment.sdoa.sdo.com/";
$data = $key1."=".val1."&".$key2."=".val2;
$Post ......
<?php
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=php100.xls");
/* echo "A1\t B1\t C1\n";
echo "A1\t B1\t C1\n";
echo "A1\t B1\t C1\n";
*/
?>
<!--*********************************************±¨±í***************************************** ......
//½«ÍøÖ·µÄ²ÎÊýתΪ±äÁ¿,Èç:xxx.php?a=1&b=2,
//ÔËÐз½·¨ºó,echo $a."|".$b, ½á¹û:1|2
extract($_GET);
//unicodeתutf8£¬Èç:中»ò \u9865 ת ³É ÖÐÎÄ
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|&#x.{4};|&am ......