PHPÖÐÎĽØÈ¡£¬UTF8ºÍGBKÏê½â
ÖÐÎÄ×Ö·û½ØÈ¡ÊÇÒ»¸öÊ®·ÖÓÐÓõŦÄÜ£¬ÔںܶàµØ·½¶¼»áÓõ½£¬±ÈÈçÌáÈ¡¶¨³¤±êÌ⣬³éÈ¡±êÇ©µÈ
ÓÉÓÚ¸÷ÖÖ×Ö·û¼¯µÄ´æ´¢·½Ê½µÄ²»Ò»Ñù£¬´æÔÚË«×Ö½Ú£¨GBK£©¶à×Ö½Ú£¨Unicode£©µÄ´æ´¢·½Ê½£¬Õâ¾Íµ¼ÖÂÁËͳһ´¦ÀíµÄÀ§ÄÑ¡£
¹ú¼Ê±ê×¼UTF8×Ö·û±àÂëÖУ¬´æ´¢ÖÐÎÄ×Ö·ûÒª3¸ö×Ö½Ú£¬¼´°ÑphpÎļþ´æ´¢ÎªUTF8±àÂë¸ñʽ¿ÉÒԵõ½
strlen("ÖÐ")=3
¼ÙÈçÖ±½ÓÓÃphpµÄ×Ö·û´®º¯ÊýÈ¥´¦ÀíÀàËÆÕâ¸ö×Ö·û½«¿ÉÄܲúÉúÂÒÓѵÄÇé¿ö£¬Ö÷ÒªÊÇÓÉÓÚÔÚÒ»¸öÍêÕû×Ö·ûÖмäÇ¿ÖƽضϲúÉú°ë×Ö·ûµÄÇé¿ö¡£Òª±ÜÃâÕâÖÖÇé¿öµÄΨһ°ì·¨¾ÍÊǰѽضÏλÖÃÑÓ³¤µ½Õâ¸ö×Ö·û½áÊøµÄλÖýøÐнضÏ
ÔÚPHPÖУ¬ÌṩÁËmbstringÄ£¿é¹¦ÄÜ£¬mbstringÒÔ×Ö·û×÷Ϊ²Ù×÷µÄ»ù±¾µ¥Ôª£¬Èçmb_strlen("ÖÐ","utf-8")=1
¡£
´ó²¿·ÖµÄmbstring¶¼ÒªÇóÊäÈë±àÂ룬µ±È»¿ÉÒÔÔÚphp»·¾³ÖÐÉèÖÃĬÈϵıàÂë¡£²ÎÊýÉèÖÃΪmbstring.internal_encoding
= UTF-8£¬¡¡mbstring.http_input = UTF-8£¬¡¡mbstring.http_output =
UTF-8£¬¡¡mbstring.substitute_character =
UTF-8¡£ÓÉÓÚphpϵͳһ°ãÊÇ´æ´¢×Ö½ÚÀ´¼ÆË㳤¶ÈµÄ£¬ÎªÁËÏû³ýmbstringºÍstringÖ®¼äµÄ²îÒ죬ʹÓÃmbstringµÄʱºò¾ÍÒª¸ñÍâСÐÄ
ÁË¡£
¼ÙÈ粻ʹÓÃmbstringµÄ¹¦ÄÜ µÄ»°£¬¿ÉÒÔ×ÔÐбàдÖÐÎÄ×Ö·û´¦ÀíµÄº¯Êý¡£
phpÖÐÎĽØÈ¡º¯Êý£¬¾ÍøÉÏËÑË÷ѧϰ·¢ÏÖ£¬´ó²¿·ÖÍøÂçÖж¼ÊÇÒÔ´Ó¿ªÊ¼Î»ÖÃÒ»¸öÒ»¸öÍêÕû×Ö·ûÀ´ÊµÏֵġ£ÕâÓпÉÄܵ¼ÖÂЧÂÊÊ®·Öµ×¡£ÏÂÃæÎÒдÁ˸ö½ØÈ¡º¯Êý,ÊÇÕë¶ÔUTF8µÄ
<?php
$str = "dÖУÔÚfÔÚÄãÊÇdÎҵĹú¼ÒÀ§gÔÚÓкͣ¬ÈË¡£¹¤";
var_dump(strcut($str,0,9));
function strcut($str,$start,$len){
if($start < 0)
$start = strlen($str)+$start;
$retstart = $start+getOfFirstIndex($str,$start);
echo $retstart;
$retend = $start + $len -1 + getOfFirstIndex($str,$start + $len);
echo $retend;
return substr($str,$retstart,$retend-$retstart+1);
}
//ÅжÏ×Ö·û¿ªÊ¼µÄλÖÃ
function getOfFirstIndex($str,$start){
$char_aci = ord(substr($str,$start-1,1));
if(223<$char_aci && $char_aci<240)
return -1;
$char_aci = ord(substr($str,$start-2,1));
if(223<$char_aci && $char_aci<240)
return -2;
return 0;
}
?>
224£239ÊÇUTF8ÖÐÎÄ×Ö·û¸ß루µÚһ룬¹²Èý룩asciiÇø¼ä£¬»»Ëã³ÉÊ®Áù½øÖÆΪ0xE0 - 0xEF ¶þ½øÖÆΪ1100 0000 - 1100 FFFF¡£Í¨
Ïà¹ØÎĵµ£º
Ëæ ×ÅÍøÕ¾·ÃÎÊÁ¿µÄ¼Ó´ó£¬Ã¿´Î´ÓÊý¾Ý¿â¶ÁÈ¡¶¼ÊÇÒÔЧÂÊ×÷Ϊ´ú¼ÛµÄ£¬ºÜ¶àÓÃACCESS×÷Êý¾Ý¿âµÄ¸ü»áÉîÓÐÌå»á£¬¾²Ì¬Ò³¼ÓÔÚËÑË÷ʱ£¬Ò²»á±»ÓÅÏÈ¿¼ÂÇ¡£»¥ÁªÍøÉÏÁ÷ ÐеÄ×ö·¨Êǽ«Êý¾ÝÔ´´úÂëдÈëÊý¾Ý¿âÔÙ´ÓÊý¾Ý¿â¶ÁÈ¡Éú³É¾²Ì¬Ã棬ÕâÑùÎÞÐμä¾Í¼Ó´óÁËÊý¾Ý¿â¡£½«ÏÖÓеÄASPÒ³Ö±½ÓÉú³É¾²Ì¬Ò³£¬½«»á½ÚÊ¡ºÜ¶à¡£
ÏÂÃæµÄÀý×ÓÊǽ«¡¢index.asp?i ......
Îļþ¶ÁÈ¡º¯Ê½
//Îļþ¶ÁÈ¡º¯Ê½
function PHP_Read($file_name) {
$fd=fopen($file_name,r);
while($bufline=fgets($fd, 4096)){
$buf.=$bufline;
}
fclose($fd);
return $buf;
}
& ......
ÈçºÎÅжÏipµØÖ·ºÏ·¨ÐÔ
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
emailµÄÕýÔòÅжÏ
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);
¼ì²âipµØÖ·ºÍmaskÊÇ·ñºÏ·¨µÄÀý×Ó
$ip = '192.168.0.84';
$mask = '255.255.255.0';
$network = '192.168.0';
$ip = ......
ÔÀí
Ò»°ã£¬ÓÐ2ÖÖ·½·¨¿ÉÒÔµ¼³ödocÎĵµ£¬Ò»ÖÖÊÇʹÓÃcom£¬²¢ÇÒ×÷ΪphpµÄÒ»¸öÀ©Õ¹¿â°²×°µ½·þÎñÆ÷ÉÏ£¬È»ºó´´½¨Ò»¸öcom£¬µ÷ÓÃËüµÄ·½·¨¡£°²×°¹ýofficeµÄ·þÎñÆ÷¿ÉÒÔµ÷ÓÃÒ»¸ö½Ðword.applicationµÄcom£¬¿ÉÒÔÉú³ÉwordÎĵµ£¬²»¹ýÕâÖÖ·½Ê½ÎÒ²»ÍƼö£¬ÒòΪִÐÐЧÂʱȽϵͣ¨ÎÒ²âÊÔÁËһϣ¬ÔÚÖ´ÐдúÂëµÄʱºò£¬·þÎñÆ÷»áÕ ......
±¾º¯ÊýÒÔ pattern µÄ¹æÔòÀ´½âÎö±È¶Ô×Ö·û´® subject¡£±È¶Ô½á¹û·µ»ØµÄÖµ·ÅÔÚÊý×é²ÎÊý matches Ö®ÖУ¬matches[0] ÄÚÈݾÍÊÇÔ×Ö·û´® subject¡¢matches[1] ΪµÚÒ»¸öºÏºõ¹æÔòµÄ×Ö·û´®¡¢matches[2] ¾ÍÊǵڶþ¸öºÏºõ¹æÔòµÄ×Ö·û´®£¬ÓàÀàÍÆ¡£ÈôÊ¡ÂÔ²ÎÊý matches£¬ÔòÖ»Êǵ¥´¿µØ±È¶Ô£¬ÕÒµ½Ôò·µ»ØֵΪ tr ......