21¸ö¾³£Óõ½µÄPHPº¯Êý´úÂë¶Î(2)
6. PHPÏú»ÙĿ¼
ɾ³ýÒ»¸öĿ¼£¬°üÀ¨ËüµÄÄÚÈÝ¡£
/***** *@dir ¨C Directory to destroy *@virtual[optional]- whether a virtual directory */ function destroyDir($dir, $virtual = false) { $ds = DIRECTORY_SEPARATOR; $dir = $virtual ? realpath($dir) : $dir; $dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir; if (is_dir($dir) && $handle = opendir($dir)) { while ($file = readdir($handle)) { if ($file == ¡®.¡¯ || $file == ¡®..¡¯) { continue; } elseif (is_dir($dir.$ds.$file)) { destroyDir($dir.$ds.$file); } else { unlink($dir.$ds.$file); } } closedir($handle); rmdir($dir); return true; } else { return false; } }
7. PHP½âÎö JSON Êý¾Ý
Óë´ó¶àÊýÁ÷ÐÐµÄ Web ·þÎñÈç twitter ͨ¹ý¿ª·Å API À´ÌṩÊý¾ÝÒ»Ñù£¬Ëü×ÜÊÇÄܹ»ÖªµÀÈçºÎ½âÎö API Êý¾ÝµÄ¸÷ÖÖ´«Ë͸ñʽ£¬°üÀ¨ JSON£¬XML µÈµÈ¡£
$json_string=¡¯{¡°id¡±:1,¡±name¡±:¡±foo¡±,¡±email¡±:¡±foo@foobar.com¡±,¡±interest¡±:["wordpress","php"]} ¡®; $obj=json_decode($json_string); echo $obj->name; //prints foo echo $obj->interest[1]; //prints php8. PHP½âÎö XML Êý¾Ý
//xml string $xml_string=¡±<?xml version=¡¯1.0¡ä?> <users> <user id=¡¯398¡ä> <name>Foo</name> <email>foo@bar.com</name> </user> <user id=¡¯867¡ä> <name>Foobar</name> <email>foobar@foo.com</name> </user> </users>¡±; //load the xml string using simplexml $xml = simplexml_load_string($xml_string); //loop through the each node of user foreach ($xml->user as $user) { //access attribute echo $user['id'], ¡® ¡®; //subnodes are accessed by -> operator echo $user->name, ¡® ¡®; echo $user->email, ¡®<br />¡¯; }
9. PHP´´½¨ÈÕÖ¾ËõÂÔÃû
´´½¨Óû§ÓѺõÄÈÕÖ¾ËõÂÔÃû¡£
function create_slug($string){ $slug=preg_replace(¡®/[^A-Za-z0-9-]+/¡¯, ¡®-¡¯, $string); return $slug; }
10. PHP»ñÈ¡¿Í»§¶ËÕæʵ IP µØÖ·
¸Ãº¯Êý½«»ñÈ¡Óû§µÄÕæʵ IP µØÖ·£¬¼´±ãËûʹÓôúÀí·þÎñÆ÷¡£
function getRealIpAddr() { if (!emptyempty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; }
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ