PHP SPL±Ê¼Ç
Õ⼸Ì죬ÎÒÔÚѧϰPHPÓïÑÔÖеÄSPL
¡£
Õâ¸ö¶«Î÷Ó¦¸ÃÊôÓÚPHPÖеĸ߼¶ÄÚÈÝ£¬¿´ÉÏÈ¥ºÜ¸´ÔÓ£¬µ«ÊǷdz£ÓÐÓã¬ËùÒÔÎÒ×öÁ˳¤Æª±Ê¼Ç¡£²»È»¼Ç²»×¡£¬ÒÔºóÒªÓõÄʱºò£¬»¹ÊÇÒª´ÓͷѧÆð¡£
ÓÉÓÚÕâÊǹ©×Ô¼º²Î¿¼µÄ±Ê¼Ç£¬²»Êǽ̳̣¬ËùÒÔдµÃ±È½Ï¼òµ¥£¬Ã»Óжà½âÊÍ¡£µ«ÊÇÎÒÏ룬Èç¹ûÄãÊÇÒ»¸öÊìÁ·µÄPHP5³ÌÐòÔ±£¬Ó¦¸Ã×ãÒÔ¿´¶®ÏÂÃæµÄ²ÄÁÏ£¬¶øÇһᷢÏÖËüºÜÓÐÓá£ÏÖÔÚ³ý´ËÖ®Í⣬ÍøÉϸù±¾Ã»ÓÐÈκÎÉîÈëµÄSPLÖÐÎĽéÉÜ¡£
================
PHP SPL±Ê¼Ç
Ŀ¼
µÚÒ»²¿·Ö ¼ò½é
1. ʲôÊÇSPL£¿
2. ʲôÊÇIterator£¿
µÚ¶þ²¿·Ö SPL Interfaces
3. Iterator½çÃæ
4. ArrayAccess½çÃæ
5. IteratorAggregate½çÃæ
6. RecursiveIterator½çÃæ
7. SeekableIterator½çÃæ
8. Countable½çÃæ
µÚÈý²¿·Ö SPL Classes
9. SPLµÄÄÚÖÃÀà
10. DirectoryIteratorÀà
11. ArrayObjectÀà
12. ArrayIteratorÀà
13. RecursiveArrayIteratorÀàºÍRecursiveIteratorIteratorÀà
14. FilterIteratorÀà
15. SimpleXMLIteratorÀà
16. CachingIteratorÀà
17. LimitIteratorÀà
18. SplFileObjectÀà
µÚÒ»²¿ ¼ò½é
1. ʲôÊÇSPL£¿
SPLÊÇStandard PHP Library£¨PHP±ê×¼¿â£©µÄËõд¡£
¸ù¾Ý¹Ù·½¶¨Ò壬ËüÊÇ“a collection of interfaces and classes that are meant to solve
standard
problems”¡£µ«ÊÇ£¬Ä¿Ç°ÔÚʹÓÃÖУ¬SPL¸ü¶àµØ±»¿´×÷ÊÇÒ»ÖÖʹobject£¨ÎïÌ壩ģ·Âarray£¨Êý×飩ÐÐΪµÄinterfacesºÍclasses¡£
2. ʲôÊÇIterator£¿
SPLµÄºËÐĸÅÄî¾ÍÊÇIterator¡£ÕâÖ¸µÄÊÇÒ»ÖÖDesign Pattern£¬¸ù¾Ý¡¶Design
Patterns¡·Ò»ÊéµÄ¶¨Ò壬IteratorµÄ×÷ÓÃÊÇ“provide an object which traverses some aggregate
structure, abstracting away assumptions about the implementation of that
structure.”
wikipediaÖÐ˵£¬"an iterator is an object which allows a programmer to traverse
through all the elements of a collection, regardless of its specific
implementation".……"the iterator pattern is a design pattern in which iterators
are used to access the elements of an aggregate object sequentially without
exposing its underlying representation".
ͨË×µØ˵£¬IteratorÄܹ»Ê¹Ðí¶à²»Í¬µÄÊý¾Ý½á¹¹£¬¶¼ÄÜÓÐͳһµÄ²Ù×÷½çÃ棬±ÈÈçÒ»¸öÊý¾Ý¿âµÄ½á¹û¼¯¡¢Í¬Ò»¸öĿ¼ÖеÄÎļþ¼¯¡¢»òÕßÒ»¸öÎı¾ÖÐÿһÐй¹³ÉµÄ¼¯ºÏ¡£
Èç
Ïà¹ØÎĵµ£º
Ò»¡¢ÒýÂÛ
PHP,Ò»ÃÅ×î½ü¼¸ÄêÐËÆðµÄwebÉè¼Æ½Å±¾ÓïÑÔ,ÓÉÓÚËüµÄÇ¿´óºÍ¿ÉÉìËõÐÔ,½ü¼¸ÄêÀ´µÃµ½³¤×ãµÄ·¢Õ¹,phpÏà±È´«Í³µÄaspÍøÕ¾,ÔÚËÙ¶ÈÉÏÓоø¶ÔµÄÓÅÊÆ,Ïëmssqlת6ÍòÌõÊý¾ÝphpÈçÐèÒª40Ãë,asp²»ÏÂ2·ÖÖÓ.µ«ÊÇ,ÓÉÓÚÍøÕ¾µÄÊý¾ÝÔ½À´Ô½¶à,ÎÒÃÇ¿ÊÇóÄܸü¿ìËٵĵ÷ÓÃÊý¾Ý,²»±ØҪÿ´Î¶¼´ÓÊý¾Ý¿âµô,ÎÒÃÇ¿ÉÒÔ´ÓÆäËûµÄµØ·½,±È·½Ò»¸öÎļþ,»òÕßij¸ ......
PHP °æ±¾¸÷Ò죬ÒѾֹͣÉý¼¶¿ª·¢µÄÓÐ 4.0 ϵÁÐµÄ 4.4.x£¬µ«ÏÖÔÚ»¹Óв¿·ÖÉú²ú»·¾³ÔÚÅÜÕâ¸ö°æ±¾£¬ÐèÒª¼ÌÐøά»¤´úÂë¡£PHP 5.0 ϵÁÐÊÇÏÖÔÚ¿ª·¢ºÍÓ¦ÓõÄÖ÷Á÷°æ±¾£¬ÓÐ 5.1.x ºÍ 5.2.x ϵÁС£PHP 6.0 Ä¿Ç°»¹ÊÇÊÔÓð汾£¬Óà PHP ¿ª·¢Èí¼þ²úÆ·µÄÈËÏÖÔÚ¿ÉÒÔÔ¤ÏÈ×÷¼æÈÝÐÔ²âÊÔ¡£
PHP Ö§³ÖµÄÊý¾Ý ......
$ip = "1.1.1.255".chr(0)."haha";
if(ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$",$ip)) {
echo $ip;
} else {
echo "unknown";
}
Õâ¸öeregÕýÔòÏÞÖÆÁË$ipµÄÊý¾ÝΪxxx.xxx.xxx.xxxÕâÑùµÄÐÎʽ£¬±íÃæÉÏ¿´ÉÏÃæµÄ´úÂëÓ¦¸ÃÊä³ö"unknown"£¬¶øʵ¼ÊÈ´Êä³öÁË"1.1.1.255haha"£¬ÒòΪeregº¯Êý´æÔÚNULL½Ø¶Ï ......
1 echo();2 print();3 die();4 printf();5 sprintf();6 print_r();7 var_dump();
1 echo()
¿ÉÒÔͬʱÊä³ö¶à¸ö×Ö·û´®,¿ÉÒÔ¶à¸ö²ÎÊý,²¢²»ÐèÒªÔ²À¨ºÅ,ÎÞ·µ»ØÖµ¡£
2 print()
Ö»¿ÉÒÔͬʱÊä³öÒ»¸ö×Ö·û´®£¬Ò»¸ö²ÎÊý,ÐèÒªÔ²À¨ºÅ,Óзµ»ØÖµ,µ±ÆäÖ´ÐÐʧ°Üʱ·µflase .print µÄÓ÷¨ºÍCÓï ......