PHPѧϰ(11) ×Ö·û´®±È½ÏºÍ²éÕÒ
ÔÚPHPÖУ¬¿ÉÒÔÓÃ==£¨Ë«µÈºÅ£©»òÕß ===£¨ÈýµÈºÅ£©À´±È½Ï×Ö·û´®¡£Á½ÕßµÄÇø±ðÊÇË«µÈºÅ²»±È½ÏÀàÐÍ£¬ÈýµÈºÅ»á±È½ÏÀàÐÍ£¬Ëü²»×ª»»ÀàÐÍ£»ÓÃË«µÈºÅ½øÐбȽÏʱ£¬Èç¹ûµÈºÅ×óÓÒÁ½±ßÓÐÊý×ÖÀàÐ͵ÄÖµ£¬ ¸Õ»á°ÑÁíÒ»¸öֵת»¯ÎªÊý×Ö£¬È»ºó½øÐбȽϡ£ÕâÑùµÄ»°£¬Èç¹ûÊÇ´¿×Ö·û´®»òÕßNULLʱ£¬»áת»¯Îª0½øÐбȽϡ£Í¬Ñù£¬´óСÓÚºÅÒ²ºÍµÈºÅÒ»Ñù£¬±È½Ïʱ¿ÉÄܳöÏÖ²» ÕýÈ·µÄ½á¹û¡£
ËùÒÔ£¬±È½Ï×Ö·û´®¿ÉÒÔÓÃPHPµÄ×Ô´øº¯ÊýstrcmpºÍstrcasecmp¡£ÆäÖÐstrcasecmpÊÇstrcmpµÄ±äÖÖ£¬Ëü»áÏÈ°Ñ×Ö·û´®×ª»¯ÎªÐ¡Ð´ÔÙ½øÐбȽϡ£ ÈçÏ´úÂ룺
var_dump(0 == 'Test'); var_dump(0 == ''); var_dump(5 > 'T'); var_dump(strcmp(5, 'T'));½á¹ûΪ£¨µÚ1¡«3½á¹ûÊDz»¶ÔµÄ£¬Ö»ÓеÚ4¸öÊǶԵģ©
bool(true) bool(true) bool(true) int(-1)2. ×Ö·û´®´¦Àí
£±.¡¡×Ó´®
$sub = substr(string, start[, length]);
£².¡¡×Ó´®Ìæ»»
$newstring = substr_replace(string, new, start[, length]);
ÓÃÕâ¸öº¯Êý¿ÉÒÔʵÏÖ×Ö·û´®µÄ²åÈ룬ɾ³ý²Ù×÷¡£Õâ¸öº¯ÊýµÄstartºÍlength¿ÉÒÔΪ¸ºÊý¡£·Ö±ð±íʾ´Óºó¿ªÊ¼¼ÆËãÒÔ¼°±£Áô×îºó¼¸Î»²»Ìæ»»¡£ £³.¡¡×Ö·û´®·´Ðò
$newstring = strrev(string);
£´.¡¡Öظ´×Ö·û´®
$newstring = str_repeat(string, count);
·µ»ØÒ»¸öÖظ´count´ÎstringµÄÐÂ×Ö·û´®¡£
£µ.¡¡Ìî³ä×Ö·û´®
$newstring = str_pad(to_pad, length[, with[, type]]);
ÆäÖÐtypeÓУºSTR_PAD_RIGHT£¨Ä¬ÈÏ£©¡¢STR_PAD_LEFTºÍSTR_PAD_BOTHÈýÖÖ£»withĬÈÏΪ¿Õ¸ñ¡£º¯Êý±íʾ°Ñto_pad×Ö·û´®ÓÃwithÌî³äΪһ¸ö³¤¶ÈΪlengthµÄ×Ö·û´®¡£ ÈçÏ´úÂ룺
// ×Ó´® var_dump(substr('1234567890', 8)); // 90 var_dump(substr('1234567890', 0, 2)); // 12 // ·´·½Ïò×Ó´® var_dump(substr('1234567890', -8)); // 34567890 var_dump(substr('1234567890', -8, -2)); // 345678 var_dump(substr('1234567890', -8, 2)); // 34 // ²åÈë var_dump(substr_replace('1234567890', 'a', 0, 0)); // a1234567890 // ɾ³ý var_dump(substr_replace('1234567890', '', 8)); // 12345678 // ·´·½Ïòɾ³ý var_dump(substr_replace('1234567890', '', -2, -1)); // 123456780 // Ìæ»» var_dump(substr_replace('1234567890', 'a', 0, 1)); // a234567890 // ·´·½ÏòÌæ»» var_dump(substr_replace('1234567890', 'a', -2, -1)); // 12345678a0 // ×Ö·û´®·´×ª var_dump(strrev('1234567890')); // 0987654321 // Öظ´×Ö·û´® var_dump(str_repeat('12', 3)); // 121212 // Ìî³ä×Ö·û´® var_dump(str_pad('a', 10, '12')); // a121212121 var_dump(str_pad('a', 10, '12', STR_PAD_LEFT)); // 121212121a var_dump(str_pad('a', 10, '12', STR_PAD_BOTH)); // 1212a121213. ·Ö½â×Ö·û´®
ÔÚPHPÖУ¬×Ö·û´®µÄ·Ö½âÓÃexplode£¬ºÏ²¢ÓÃimplode£¨joinÊÇimplodeµÄ±ðÃû£©£¬±ê¼ÇÓÃstrtok¡£»¹ÓÐÁíÒ»¸öº¯ÊýsliptÒ²¿ÉÒԷֽ⣨ÕýÔò·Ö½â£©£¬µ«5.3ÒÔºó°æ±¾ÒѾ²»ÍƽéÁË¡£ ÁíÍâPHPÖл¹ÓÐÒ»¸össcanf()º¯Êý£¬ÓÃÓÚ¶ÁÈ¡×Ö·û´®¡£
strtok±ê¼Çʱ£¬ÓÃstrtok($str, $token)À´³õʼ»¯£¬ÓÃstrtok($token)À´¼ÌÐøÈ¡Öµ¡£
´úÂëÈçÏ£º
$str = '1,2,3'; $arr1 = explode(',', $str); // array('1', '2', '3') $arr2 = explode(',', $str, 2); // array('1', '2,3') $str1 = implode(',', $arr1); // '1,2,3' $str2 = strtok($str, ','); // 1 $str3 = strtok(','); // 2 $str4 = strtok(','); // 3 // array(86, 10, 88888888, 'Beijin') $arr3 = sscanf('+86(10)88888888 Beijin', '+%d(%d)%d %s');4.×Ö·û´®²éÕÒ
ÔÚPHPÖУ¬×Ö·û´®µÄ²éÕÒÓÐÈý¸öϵÁС£·µ»ØλÖõġ¢·µ»Ø×Ö·û´®µÄ¡¢ÑÚÂë¸öÊýÆ¥Åä¡£ÆäÖУ¬·µ»Øλ Öõĵĺ¯ÊýÒ»¹²ÓÐÁ½¸ö£¬strpos()ºÍ strrpos()£»·µ»Ø×Ö·û´®µÄÒ²ÓÐÁ½¸östrstr()ºÍstrchr()£»·µ»ØÑÚÂëÆ¥ÅäÊýµÄº¯ÊýÓÐstrspn()ºÍstrcspn()¡£
strpos±íʾ´Ó×ó±ß¿ªÊ¼¼ÆÊý£¬·µ»ØÒª²éÕÒµÄ×Ö·û´®µÚÒ»´Î³öÏÖµÄλÖã»strrpos±íʾ´ÓÓұ߼ÆÊý£¬·µ»ØÒª²éÕÒµÄ×Ö·û´®µÚÒ»´Î³öÏÖµÄλÖá£
strstr±íʾ´Ó×ó±ß¼ÆÊý£¬·µ»ØÒª²éÕÒ×Ö·û´®µÚÒ»´Îµ½½áβµÄ×Ó´®£¨°üÀ¨²éÕÒ×Ö·û´®£©£¬µ±²éÕÒµÄÊÇ×Ö·ûʱ£¬¿ÉÒÔÓÃasciiÂëÊý×ÖÀ´±íʾ×Ö·û£»stristr±íʾ²»Çø·Ö´óС²éÕÒ£»strchrÊÇstrstrµÄ±ðÃû£»strrchr·µ»Ø×Ö·û×îºó³öÏÖµ½½áβµÄ×Ó´®¡£
strspn±íʾ´Ó×ó±ß¼ÆÊý£¬µÚÒ»´Î³öÏÖ·ÇÑÚÂë֮ǰµÄ×Ó´®µÄ×Ö·ûÊý£»strcspn±íʾ´Ó×ó±ß¼ÆÊý£¬µÚÒ»´Î³öÏÖÑÚÂë֮ǰµÄ×Ó´®µÄ×Ö·ûÊý¡£
ʾÀý´úÂ룺
$pos = strpos('This a hello world program', ' '); // 4 $pos = strpos('This a hello world program', 32); // 4 $pos = strrpos('This a hello world program', ' '); // 18 $pos = strrpos('This a hello world program', 32); // 18 $str = strstr('This a hello world program', ' '); // " a hello world program" $str = strstr('This a hello world program', 32); // " a hello world program" $str = stristr('This a hello world program', ' A'); // "a hello world program" $str = stristr('This a hello world program', 65); // "a hello world program" $str = strrchr('This a hello world program', ' '); // " program" $str = strrchr('This a hello world program', 32); // " program" $str1 = "12345 12345 12345"; $len = strspn($str1, '12345'); // 5 $len = strcspn($str1, ' '); // 5
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ