Heim  >  Artikel  >  Backend-Entwicklung  >  php字符串查找函数(strrpos与strchr)

php字符串查找函数(strrpos与strchr)

WBOY
WBOYOriginal
2016-07-25 08:54:011310Durchsuche
  1. $str = '1234567890';
  2. $needle = '234';
  3. $result = strchr($str, $needle);
  4. var_dump($result);
复制代码

结果:string '234567890'(length=9)

strrpos寻找字符串中某字符最后出现处。 语法: int strrpos(string haystack,char needle);

本函数用来寻找字符串 haystack 中的字符 needle 最后出现的位置。 注意,needle只能是一个字符,中文字等就不适合了。 若找不到指定的字符,则返回 false 值。

strpos 寻找字符串中某字符最先出现处。

语法: int strpos(string haystack,string needle, int [offset]);

本函数用来寻找字符串 haystack 中的字符 needle 最先出现的位置。 注意,needle只能是一个字符,中文字等就不适合了。若找不到指定的字符,则返回 false 值。 参数 offset 可省略,用来y表示从 offset开始找。

strspn 找出某字符串落在另一字符串遮罩的数目。

语法: int strspn(string str1,string str2);

本函数将 str2 字符串当遮罩,可用来计算 str1字符串中有几个字符落在 str2 遮罩中。 php字符串比较与查找方法详解 php比较字符串相似度的函数用法参考 PHP字符串比较函数strcmp()与strcasecmp()的用法介绍 php比较字符串相似度的实例代码



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn