zoukankan      html  css  js  c++  java
  • php -- strpos,stripos,strrpos,strripos,strstr,strchr,stristr,strrchr

    strpos() 函数

    语法:

    mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

    查找 needle 在 haystack 中第一次出现的位置。大小写敏感

    如果成功,则返回位置,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数:

    haystack:在该字符串中进行查找。

    needle:如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符的顺序值。

    offset:如果提供了此参数,搜索会从字符串该字符数的起始位置开始统计。和 strrpos()、 strripos()不一样,这个偏移量不能是负数。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = strpos($mystring, $findme); //$pos值为2
    
    $findme   = 'L';
    $pos = strpos($mystring, $findme); //$pos值为false
    
    $findme   = 'q';
    $pos = strpos($mystring, $findme); //$pos值为false

    stripos

    语法:

    mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

    查找 needle 在 haystack 中第一次出现的位置。大小写不敏感

    如果成功,则返回位置,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数:

    haystack:在该字符串中查找。

    needle:注意 needle 可以是一个单字符或者多字符的字符串。如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符顺序值。

    offset:可选的 offset 参数允许你指定从 haystack 中的哪个字符开始查找。返回的位置数字值仍然相对于haystack 的起始位置。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = stripos($mystring, $findme); //$pos值为2
    
    $findme   = 'L';
    $pos = stripos($mystring, $findme); //$pos值为2
    
    $findme   = 'q';
    $pos = stripos($mystring, $findme); //$pos值为false

    *******************************************************************************************************************

    strrpos() 函数

    语法 
    mixed strrpos ( string $haystack , string $needle [, int $offset = 0 ] )

    查找 needle 在 haystack 中最后一次出现的位置。大小写敏感

    如果成功,则返回位置,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数

    haystack:在此字符串中进行查找。

    needle:注意 needle 可以是一个单字符或者多字符的字符串。

    offset:或许会查找字符串中任意长度的子字符串。负数值将导致查找在字符串结尾处开始的计数位置处结束。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = strrpos($mystring, $findme); //$pos值为8
    
    $findme   = 'L';
    $pos = strrpos($mystring, $findme); //$pos值为false
    
    $findme   = 'q';
    $pos = strrpos($mystring, $findme); //$pos值为false

    strripos() 函数

    语法
    mixed strripos ( string $haystack , string $needle [, int $offset = 0 ] )

    查找 needle 字符串在 haystack 中最后一次出现的位置大小写不敏感

    如果成功,则返回位置,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数

    haystack:在此字符串中进行查找。

    needle:注意 needle 可以是一个单字符或者多字符的字符串。

    offset:参数 offset 可以被指定来查找字符串中任意长度的子字符串。负数偏移量将使得查找从字符串的起始位置开始,到 offset 位置为止。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = strripos($mystring, $findme); //$pos值为8
    
    $findme   = 'L';
    $pos = strripos($mystring, $findme); //$pos值为8
    
    $findme   = 'q';
    $pos = strripos($mystring, $findme); //$pos值为false

    *******************************************************************************************************************

    strstr () 函数(strchr)

    语法
    string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

    返回 needle 在 haystack 中第一次出现的位置开始到结尾的字符串。大小写敏感
    如果成功,则返回字符串,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数

    haystack:输入字符串。

    needle:如果 needle 不是一个字符串,那么它将被转化为整型并且作为字符的序号来使用。

    before_needle:若为 TRUEstrstr() 将返回 needle 在 haystack 中的位置之前的部分。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = strstr($mystring, $findme); //$pos值为lloworld
    
    $findme   = 'L';
    $pos = strstr($mystring, $findme); //$pos值为false
    
    $findme   = 'q';
    $pos = strstr($mystring, $findme); //$pos值为false

    stristr () 函数

    语法
    string stristr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

    返回 needle 在 haystack 中最后一次出现的位置到结尾的字符串。大小写不敏感。
    如果成功,则返回字符串,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数

    haystack:在该字符串中查找。

    needle:如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符顺序值。

    before_needle:若为 TRUEstrstr() 将返回 needle 在 haystack 中的位置之前的部分(不包括 needle)。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = stristr($mystring, $findme); //$pos值为lloworld
    
    $findme   = 'L';
    $pos = stristr($mystring, $findme); //$pos值为lloworld
    
    $findme   = 'q';
    $pos = stristr($mystring, $findme); //$pos值为false

    ******************************************************************************************************************* 

     

    strrchr() 函数

    语法
    string strrchr ( string $haystack , mixed $needle )

    返回 haystack 字符串中的一部分,这部分以 needle 的最后出现位置开始,直到 haystack 末尾。
    如果成功,则返回字符串,否则返回 false。

    正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写

    参数

    haystack:在此字符串中进行查找。

    needle:注意 needle 可以是一个单字符或者多字符的字符串。

    offset:参数 offset 可以被指定来查找字符串中任意长度的子字符串。负数偏移量将使得查找从字符串的起始位置开始,到 offset 位置为止。

    $mystring = 'helloworld';
    
    $findme   = 'l';
    $pos = strrchr($mystring, $findme); //$pos值为ld
    
    $findme   = 'L';
    $pos = strstr($mystring, $findme); //$pos值为false
    
    $findme   = 'q';
    $pos = strstr($mystring, $findme); //$pos值为false

     strrichr()函数 -- 没有

    ********************************************************************************************************************

  • 相关阅读:
    List of the best open source software applications
    Owin对Asp.net Web的扩展
    NSwag给api加上说明
    'workspace' in VS Code
    unable to find valid certification path to requested target
    JMeter的下载以及安装使用
    exception disappear when forgot to await an async method
    Filter execute order in asp.net web api
    记录web api的request以及response(即写log)
    asp.net web api的源码
  • 原文地址:https://www.cnblogs.com/hf8051/p/4747122.html
Copyright © 2011-2022 走看看