ÓÃphpµÄÕýÔò±í´ïʽƥÅ人×Ö
Õâ¶Îʱ¼äÊÔͼʹÓÃphpÕýÔò±í´ïʽ(Perl ¼æÈÝÕýÔò±í´ïʽº¯Êý)´¦ÀíÖÐÎÄÎı¾ÐÅÏ¢£¬ÔÚÆ¥ÅäÖÐÎÄÉÏÓöµ½Öî¶àÎÊÌ⣬ÇóÖúÓÚÍøÉϵIJο¼×ÊÁÏ£¬È»ÍøÎĶàÁ¼Ý¬²»Æ룬²¢´æÔÚÖî¶àÃýÎ󣬾¹ý¼¸ÌìµÄ̽Ë÷ºÍ²âÊÔ£¬ÖÕ ÓÚ×ܽá³öÁ˼¸ÖÖ¿ÉÓ÷½Ê½µÄ£¬Ð´Ï¹©ÓÐÐËȤÕ߲ο¼£¬Îª·×·±¸´ÔÓµÄÍøÎÄÓÖÔö¼Óһƪ¡£
1. ÁýͳµÄʹÓÃÔª×Ö·ûÆ¥ÅäÖÐÎÄ£¬/.*?/s£¬¿ÉÆ¥ÅäÒ»¶ÎÖÐÎÄ£¬ÕâÔÚANSI(gb2312)ºÍutf-8»·¾³µÄ³ÌÐò´úÂ붼¿ÉÒÔʵÏÖ¡£µ«ÌáÐÑһϣ¬\w²»ÄÜÆ¥ ÅäÖÐÎÄ¡£ÔøÔÚÒ»±¾¡¶¾«Í¨ÕýÔò±í´ïʽ¡·(ÈËÃñÓʵç³ö°æÉ磬ɳ½ð±àÖø)ÊéÉÏ¿´µ½¿ÉÒÔʹÓÃ\wÆ¥ÅäÖÐÎÄ£¬ÕâÀï¾ÀÕýÒ»ÏÂÓÃphp²»ÐС£¿ÉÒÔʹÓá±/./¡±£¬¡± /[^\d]/¡±£¬¡±/[^a]/¡±£¬Æ¥ÅäÖÐÎÄ×Ö·û¡£
2. Èç¹ûÒª¾«×¼Æ¥ÅäÖÐÎÄ£¬¼´Æ¥Åä´¿ÖÐÎÄ×Ö·û£¬»òÆ¥ÅäÖÐÎÄ×Ö·û¼ÓÉÏÈ«½Ç±êµã£¬ÔòÐèÒª¸ù¾Ý²»Í¬±àÂë»·¾³Ê¹Óò»Í¬·½·¨¡£ÏÂÃæÒÔÁ½ÖÖ³£ÓõıàÂë(gb2312,utf-8)½øÐнéÉÜ£º
ÔÚANSI(gb2312)»·¾³Ï£¬¿ÉʹÓÃ[chr(0xnn)-chr(0xmm)]µÄ·½Ê½Æ¥Å䣬ÈçÔÚһƪÍøÎÄÉϾÍÌṩÕâÑùµÄ·½ ·¨£¬¡±/[".chr(0xb0)."-".chr(0xf7)."]+/¡±£¬ÕâÊÇ¿ÉÒÔʹÓõģ¬µ«ÕâÌ«¹ýÁýͳ£¬Õâ¸ö±í´ïʽÊÇÆ¥ÅäÈ«²¿µÄgb2312±àÂë±í µÄ×Ö·û£¨gb2312±àÂë±íhttp://hi.baidu.com/gaojinshan/blog/item /5a904010327e6609213f2e8d.html£©£¬¼È°üÀ¨ºº×Ö¡¢±êµã¡¢ÈÕÎÄƽ¼ÙÃûµÈ£¬»¹ÓÐһЩ²»ÖªÊÇʲô·ûºÅµÄ¡£¶ø´Ó±àÂë±í¿ÉÒÔ¿´³öºº×Ö µÄ±àÂ뷶ΧÊÇ0xb0a1-0xf7fe£¬²¢ÇÒgb2312ÊÇÓÃÁ½¸ö×Ö½Ú½øÐбàÂëµÄ£¬Ã¿¸ö×Ö½Ú×î¸ßλ¶¼ÊÇ1 ¡£ËùÒÔ¿ÉÒÔ½å´Ëд³öµ¥´¿Æ¥Å人×ÖµÄÕýÔòʽ£º
¡°/([".chr(0xb0)."-".chr(0xf7)."][".chr(0xa1)."-".chr(0xfe)."])/¡± £¬¸Ã±í´ïʽÄÜÆ¥ÅäÒ»¸öÖÐÎÄ×Ö·û£¬ÊýÁ¿¹Øϵ¾Í¿ÉÒÔÈÝÒ×À©Õ¹ÁË¡£
²¢ÇÒ¾ÙÒ»·´Èý£¬Èç¹ûÏëÆ¥ÅäÈ«½Ç±êµã¶ø²»Æ¥ÅäÖÐÎľͿÉÒÔÕâÑùд£º
¡°/([".chr(0xa1)."-".chr(0xa3)."][".chr(0xa1)."-".chr(0xff)."])/¡±£¬¾ÍÊÇÆ¥Åä±àÂ뷶Χ0xa1a1-0xa3ffÄڵķûºÅ¡£ÆäËûµÄÀàËÆ¡£
3. ÏÂÃæ½éÉÜutf-8»·¾³ÏÂÖÐÎĵÄÆ¥Åä¡£ÀàËÆÓÚÉÏÃ棬Ҳ¿ÉÒÔʹÓÃunicode±àÂë±í£¨È«²¿±àÂë±í£¬http://hi.baidu.com/lbeny_hit/blog/item/bdb670efade0bffcb2fb95dc.html ¡£×ÖÌå±à¼ÓÃÖÐÈÕº«ºº×ÖUnicode±àÂë±í£¬http://www.chi2ko.com/tool/CJK.htm ¡££©À´È·¶¨ÖÐÎĵÄÆ¥Åä¡£ÓɱàÂë±í¿ÉÒÔ¿´³ö£¬ÖÐÎĵıàÂ뷶ΧÊÇ0x4e00-0x9fa5,ÓÚÊÇÕýÔòʽ¿ÉÒÔÕâÑùд£º
¡°/[\x{4e00}-\x{9fa5}]/u¡± £¬\x{nnnn}±íʾ×Ö·ûµÄÊ®Áù½øÖÆÐÎʽ£¬¸ü¶àÐÅÏ¢Çë×Ô¼º²é¿´phpÊֲᡣҪÌرð×¢ÒâµÄÊÇģʽÐÞÕý·ûu £¬phpÊÖ²áÀïÕâÑù˵£ºu£¨PCRE_UTF8£© ´ËÐÞÕý·ûÆôÓÃÁËÒ»¸ö PCRE ÖÐÓë Perl ²»¼æÈݵĶîÍ⹦ÄÜ¡£Ä£Ê½×Ö·û´®±»µ±³É UTF-8¡£±¾ÐÞÕý·ûÔÚ Unix ÏÂ×Ô PHP 4.1.0 Æð¿ÉÓã¬ÔÚ win32 ÏÂ×Ô PHP 4.2.3 Æð¿ÉÓá£×Ô PHP 4.3.5 Æð¿ªÊ¼¼ì²éģʽµÄ UTF-8 ºÏ·¨ÐÔ¡£ÕâÕýÊÇÕýÈ·Æ¥ÅäËù±ØÐëµÄ¡£ÆäʵҲÏëÌáÐÑһϣ¬ÊÇutf-8»·¾³Ê¹ÓÃÔª×Ö·ûÆ¥Åä×Ö·û´®×îºÃ¼ÓÉÏÐÞÕý·ûu£¬ÕâÖ»ÊǾÑé¡£
ÏÂÃæ¸øÁ½¸öÀý×Ó£º
(1) ANSI±à³Ì»·¾³ÏÂ:
$strtest = ¡°yygÖÐÎÄ×Ö·ûyyg¡±;
$pregstr = ¡°/([".chr(0xb0)."-".chr(0xf7)."][".chr(0xa1)."-".chr(0xfe)."])+/i¡±;
if(preg_match($pregstr,$strtest,$matchArray)){
echo $matchArray[0];
}
//output:ÖÐÎÄ×Ö·û
(2) Utf-8±à³Ì»·¾³ÏÂ:
$strtest = ¡°yygÖÐÎÄ×Ö·ûyyg¡±;
$pregstr = ¡°/[\x{4e00}-\x{9fa5}]+/u¡±;
if(preg_match($pregstr,$strtest,$matchArray)){
echo $matchArray[0];
}
//output:ÖÐÎÄ×Ö·û
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ