ÔÚ±à³ÌµÄ¹ý³Ìµ±ÖÐ,×Ö·û´®µÄ²Ù×÷ÊǷdz£ÖØÒªµÄ²¢ÇÒ¾³£»á±»Óõ½,×Ö·û´®³£ÓõIJÙ×÷¾ßÌåµÄ°üÀ¨×Ö·û´®µÄÆ´½Ó,Ìæ»»×Ö·û´®,²éÕÒ×Ö·û´®,±È½Ï×Ö·û´®,¸´ÖÆ×Ö·û´®ÒÔ¼°¼ÆËã×Ö·û´®µÄ³¤¶ÈµÈµÈ.
1,Æ´½Ó×Ö·û´®
Æ´½Ó×Ö·û´®ÊÇ×î³£Óõ½µÄ×Ö·û´®²Ù×÷Ö®Ò»,ÔÚPHPÖÐÖ§³ÖÈýÖÖ·½Ê½¶Ô×Ö·û´®½øÐÐÆ´½Ó²Ù×÷,·Ö±ðÊÇÔ²µã.·Ö¸ô·û{}²Ù×÷,»¹ÓÐÔ²µãµÈºÅ.=À´½øÐвÙ×÷,Ô²µãµÈºÅ¿ÉÒÔ°ÑÒ»¸ö±È½Ï³¤µÄ×Ö·û´®·Ö½âΪ¼¸ÐнøÐж¨Òå,ÕâÑù×öÊDZȽÏÓкô¦µÄ.
2,Ìæ»»×Ö·û´®
ÔÚPHPÕâÃÅÓïÑÔÖÐ,ÌṩÁËÒ»¸öÃû×Ö½Ð×ösubstr_replace()µÄº¯Êý,¸Ãº¯ÊýµÄ×÷ÓÿÉÒÔ¿ìËÙµÄÍê³ÉɨÃèºÍ±à¼Îı¾ÄÚÈݽ϶àµÄ×Ö·û´®Ìæ»»¹¦ÄÜ.ËûµÄÓï·¨¸ñʽ:
mixed substr_replace(mixed $string,string $replacement, int $start[,int $length])
¶ÔÓÚÉÏÃæµÄÓï·¨¸ñʽµÄ˵Ã÷:
string ÊÇÒª¼ì²é»òÕß½«Òª±»Ìæ»»µÄ×Ö·û´®
replacement Ö¸¶¨ÒªÓÃÀ´²åÈë»òÕßÌæ»»µÄ×Ö·û´®
start Ö¸¶¨ÔÚ×Ö·û´®µÄºÎ´¦½øÐпªÊ¼Ìæ»»,Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÈýÖÖÀàÐ͵ÄÖµ(ÕýÊý:´Ó×Ö·û´®¿ªÍ·µÄµÚstart¸öÆ«ÒÆÁ¿¿ªÊ¼Ìæ»»,¸ºÊý,´Ó×Ö·û´®½áβ´¦µÄµÚstart¸öÆ«ÒÆÁ¿¿ªÊ¼Ìæ»»,0:´Ó×Ö·û´®ÖеĵÚÒ»¸ö×Ö·û¿ªÊ¼Ìæ»»)
lengthÖ¸¶¨ÒªÌæ»»¶àÉÙ¸ö×Ö·û,Õâ¸ö²ÎÊýÒ²¿ÉÒÔÈ¡ÈýÖÖÀàÐ͵ÄÖµ(ÕýÊý:±»Ìæ»»µÄ×Ö·û´®µÄ³¤¶È,¸ºÊý:´Ó×Ö·û´®µÄ½áβ¿ªÊ¼±»Ìæ»»µÄ×Ö·û´®µÄ³¤¶È,0:ÊDzåÈë²Ù×÷,¶ø²»ÊÇÌæ»»²Ù×÷);
3,¼ÆËã×Ö·û´®
1)¼ÆËã×Ö·û´®µÄ³¤¶È
ÔÚPHPÖÐ,strlen()º¯ÊýÓÃÀ´¼ÆËã×Ö·û´®µÄ³¤¶È²¢ÇÒ·µ»Ø¸Ã×Ö·û´®µÄ³¤¶ÈÐÅÏ¢.¸ÃÓï·¨µÄ¸ñʽÈçÏÂ:int strlen(string $string)¸ñʽÀïÃæµÄstring¾ÍÊÇÓÃÀ´Ö¸¶¨Òª¼ÆË㳤¶ÈµÄ×Ö·û´®.
2)¼ÆËã×Ö·û´®µÄÊýÄ¿
ÔÚPHPÖÐ,substr_count()º¯Êý,¿ÉÒÔÓÃÀ´·Ç³£·½±ã¶øÇÒ׼ȷµÄÈ·¶¨Ò»¸öÖ¸¶¨µÄ×Ó×Ö·û´®ÔÚËùÌṩµÄ×Ö·û´®ÖÐÓжàÉÙ¸ö,substr_count()º¯ÊýµÄÓï·¨¸ñʽÈçÏÂ:int substr_count(string $haystack,string $needle[,int $offset=0[,int $length]])ÔÚÉÏÃæµÄÓï·¨ÖÐÉè¼ÆµÄ²ÎÊýµÄ˵Ã÷ÈçÏÂ:haystackÖ¸¶¨Òª¼ì²éµÄ×Ö·û´®,needleÓÃÀ´Ö¸¶¨Òª²åÈëµÄ×Ö·û´®,offsetÓÃÀ´Ö¸¶¨ÔÚ×Ö·û´®Öкδ¦¿ªÊ¼ËÑË÷,ĬÈÏֵΪ0,lengthÓÃÀ´Ö¸¶¨ËÑË÷µÄ³¤¶È.
ÔÚPHPÖÐ,str_word_count()º¯Êý,¿ÉÒÔÓÃÀ´·Ç³£·½±ã¶øÇÒ׼ȷµÄÈ·¶¨Ò»¸öijһ¸öµ¥´ÊÔÚËùÌṩµÄ×Ö·û´®ÖÐÓжàÉÙ¸ö,str_word_count()º¯ÊýµÄÓï·¨¸ñʽÈçÏÂ:mixed str_word_count(string $string[,int $format=0[,string $charlist]])ÔÚÉÏÃæµÄÓï·¨ÖÐÉæ¼°µ½µÄ²ÎÊýµÄ˵Ã÷ÈçÏÂ:stringÓÃÀ´Ö¸¶¨Òª½øÐмì²éµÄ×Ö·û´®,formatÓÃÀ