PHP ÕýÔòÅжÏÖÐÎÄ UTF 8 & GBK
UTF-8Æ¥Åä: ÔÚjavascriptÖУ¬ÒªÅжÏ×Ö·û´®ÊÇÖÐÎÄÊǺܼòµ¥µÄ¡£±ÈÈ磺
var str = "php±à³Ì";
if (/^[\u4e00-\u9fa5]+$/.test(str)) {
alert("¸Ã×Ö·û´®È«²¿ÊÇÖÐÎÄ");
}
else{
alert("¸Ã×Ö·û´®²»È«²¿ÊÇÖÐÎÄ");
} phpÖУ¬ÊÇÓÃ\x±íʾʮÁù½øÖÆÊý¾ÝµÄ¡£ÓÚÊÇ£¬±ä»»³ÉÈçϵĴúÂ룺
$str = "php±à³Ì";
if (preg_match("/^[\x4e00-\x9fa5]+$/",$str)) {
print("¸Ã×Ö·û´®È«²¿ÊÇÖÐÎÄ");
} else {
print("¸Ã×Ö·û´®²»È«²¿ÊÇÖÐÎÄ");
}
òËƲ»±¨´íÁË£¬ÅжϵĽá¹ûÒ²ÕýÈ·£¬²»¹ý°Ñ$str»»³É“±à³Ì”Á½×Ö£¬½á¹ûÈ´»¹ÊÇÏÔʾ“¸Ã×Ö·û´®²»È«²¿ÊÇÖÐÎÄ”£¬¿´À´ÕâÑùµÄÅжϻ¹ÊDz»¹»×¼È·¡£ÖØÒª:²éÔÄÁË<¾«Í¨ÕýÔò±í´ïʽ>·¢ÏÖ,¶ÔÓÚ[\x4e00-\x9fa5]Õâ¿é¶«Î÷,×Ô¼º×öÒ»¸öÇ¿»¯µÄ½âÊÍ phpµÄÕýÔòÖÐ, [\x4e00-\x9fa5],Æäʵ¾ÍÊÇ ×Ö·ûºÍ×Ö·û×éµÄ¸ÅÄî, \x{hex},±í´ïÒ»¸ö16½øÖÆÊý, ÐèҪעÒâµÄÊÇhex ¿ÉÒÔÊÇ1-2λµÄ,Ò²¿ÉÒÔÊÇ4λµÄ,µ«ÊÇÈç¹ûÊÇ4λµÄ±ØÐë¼ÓÉÏ´óÀ¨ºÅ, ͬʱ,Èç¹ûÊÇ´óÓÚx{FF}µÄhex,±ØÐëºÍu ÐÞÊηûÁ¬ÓÃ,²»È»»á·Ç·¨³ö´í
ÍøÉÏÖ»ÄÜÕÒµ½Æ¥ÅäÈ«½Ç×Ö·ûµÄÕýÔò: ^[\x80-\xff]*^/ ,ÕâÀï¿ÉÒÔ²»¼Ó´óÀ¨ºÅ
[\u4e00-\u9fa5]¿ÉÒÔÆ¥ÅäÖÐÎÄ,µ«ÊÇPHPÓÖ²»Ö§³Ö
²»¹ý£¬¼ÈÈ»\x±íʾµÄÊ®Áù½øÖÆÊý¾Ý£¬ÎªÊ²Ã´ºÍjsÀï±ßÌṩµÄ·¶Î§\x4e00-\x9fa5²»Ò»ÑùÄØ£¿ÓÚÊÇÎҾͻ»³ÉÁËϱߵĴúÂë,·¢ÏÖÕæµÄ׼ȷÁË£º
$str = "php±à³Ì";
if (preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)) {
print("¸Ã×Ö·û´®È«²¿ÊÇÖÐÎÄ");
} else {
print("¸Ã×Ö·û´®²»È«²¿ÊÇÖÐÎÄ");
} ÖªµÀÁËphpÖÐutf-8±àÂëÏÂÓÃÕýÔò±í´ïʽƥÅ人×ÖµÄ×îÖÕÕýÈ·±í´ïʽ——/^[\x{4e00}-\x{9fa5}]+$/u£¬
²Î¿¼ÒÔÉÏÎÄÕÂдÁËÈçÏÂÒ»¶Î²âÊÔ´úÂë(¸´ÖÆÒÔÏ´úÂë±£´æ³É.phpÎļþ) <?php
$action = trim($_GET['action']);
if($action == "sub")
{
$str = $_POST['dir'];
//if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/",$str)) //GB2312ºº×Ö×ÖĸÊý×ÖÏ»®ÏßÕýÔò±í´ïʽ
if(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$str)) //UTF-8ºº×Ö×ÖĸÊý×ÖÏ»®ÏßÕýÔò±í´ïʽ
{
echo "<font color=red>ÄúÊäÈëµÄ[".$str."]º¬ÓÐÎ¥·¨×Ö·û</font>";
}
&
Ïà¹ØÎĵµ£º
×°ÁËPHP-5.3.0, Æô¶¯µÄʱºò×ÜÊÇ»áÓÐ
"[06-Aug-2009 13:27:31] PHP Warning: PHP Startup: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are stil ......
×÷ÕߣºMartin Streicher, Èí¼þ¿ª·¢ÈËÔ±, Pixel, Byte, and Comma
¾¡¹Ü±àдһ¸ö PHP À©Õ¹²¢²»ÊǺÜÀ§ÄÑ£¬¶ø SWIG µÄÈ·½øÒ»²½¼ò»¯ÁËÕâÏîÈÎÎñ£¬ÕâÖ÷ÒªÊÇÒòΪËü×Ô¶¯»¯Á˽áºÏ PHP Óë C »ò C++ ËùÐèµÄ¹¤×÷¡£Èô¸ø¶¨¶ÔÒ»¸öº¯ÊýµÄÃè»æ — º¯ÊýµÄÃû³Æ¼°ÆäÐβΠ— SWIG ¾Í»áÉú³ÉÒ»¸ö°ü×°³ÌÐòÀ´½« PHP ÓëµÍ²ã´úÂëÁ¬½ÓÆðÀ´¡£
......
ÕýºÃ¹¤×÷ÖÐÅäµ½´ËÀàÎÊÌ⣬д³öÀ´ºÍ´ó¼Ò·ÖÏí¡£ºÜ¶àÍøÓÑÌṩÁËʹÓÃurlencode ºÍ urldecodeµÄ·½Ê½È¥±àÂëºÍ½âÂ룬˵µÄ²»È«Ãæ¡£ÓеÄʱºòÒ²»áÅöµ½ÕâÑùµÄÎÊÌâ¡£
1.Ê×ÏÈÒª¼ì²éÄãapacheºÍphpµÄ·þÎñÆ÷ĬÈÏÓïÑÔ¡£ÔÚwindowÏ£¬¿ÉÒԲο¼apacheµÄÅäÖÃÎļþhttpd.conf¡£ ÔÚAddCharset¸½½üÔÚ¼ÓÉÏÏÂÃæµÄÃüÁîÐУº
AddDefaultCharset UTF-8
......
תÌû£¬ÔÎijö´¦ÈçÏ£º
http://web-developer.csdn.net/?p=161
°²×° PHP Ó¦ÓóÌÐò·þÎñÆ÷ (Windows)
ÈôÒª´¦Àí¶¯Ì¬ Web Ò³£¬ÄúÐèÒªÓ¦ÓóÌÐò·þÎñÆ÷¡£Ó¦ÓóÌÐò·þÎñÆ÷ÊÇÒ»ÖÖÈí¼þ£¬Ëü°ïÖú Web ·þÎñÆ÷´¦Àí°üº¬·þÎñÆ÷¶Ë½Å±¾»ò±êÇ©µÄ Web
Ò³¡£µ±ä¯ÀÀÆ÷ÇëÇóÕâÑùÒ»¸öҳʱ£¬Web ·þÎñÆ÷ÏȽ«¸ÃÒ³´«µÝ¸øÓ¦ÓóÌÐò·þÎñÆ÷½øÐд¦Àí£¬È ......
ÔÚPHPÖÐÐÞ²¹XSS©¶´£¬ÎÒÃÇ¿ÉÒÔʹÓÃÈý¸öPHPº¯Êý¡£
¡¡¡¡ÕâЩº¯ÊýÖ÷ÒªÓÃÓÚÇå³ýHTML±êÖ¾£¬ÕâÑù¾Íû°ì·¨×¢Èë´úÂëÁË¡£Ê¹Óøü¶àµÄº¯ÊýÊÇhtmlspecialchars() £¬Ëü¿ÉÒÔ½«ËùÓеÄ"<"Óë">"·ûºÅת»»³É"<" Óë">;"¡£ÆäËü¿É¹©Ñ¡ÔñµÄº¯Êý»¹ÓÐhtmlentities(), Ëü¿ÉÒÔÓÃÏàÓ¦µÄ×Ö·ûʵÌå(entities)Ìæ»»µôËùÓÐÏëÒªÌæ»»µôµÄÌØÕ÷Âë(cha ......