zoukankan      html  css  js  c++  java
  • php中判断一个字符是否在字符串中

    1. strpos() - 查找字符串在另一字符串中第一次出现的位置(区分大小写)

    2. stripos() - 查找字符串在另一字符串中第一次出现的位置(不区分大小写)

    3. strrpos() - 查找字符串在另一字符串中最后一次出现的位置(区分大小写)

    4. strripos() - 查找字符串在另一字符串中最后一次出现的位置(不区分大小写)

    参数:
    strripos(string,find,start)
    string:必需。规定要搜索的字符串。
    find:必需。规定要查找的字符。
    start:可选。规定开始搜索的位置。

    例子:

    1#

    <?php
    $str = 'abcdef';
    $find   = 'abc';
    $pos = strpos($mystring, $findme);

    // 注意这里使用的是 ===不能使用==
    // 因为如果没有
    字符串 就返回false,如果这个字符串位于字符串的开始的地方,就会返回0为了区分0和false就必须使用等同操作符 === 或者 !==

    if ($pos === false) {
        echo "$find不在$str中";
    } else {
        echo "$find在$str";
    }
    ?>

    2#

    <?php
    $string = 'abcdef abcdef';
    $find = strpos($string,'a',1); // $find = 7, 不是 0
    ?>

    
    
  • 相关阅读:
    [转]
    Linux
    [转]
    [转]
    Linux 高级网络编程
    [转]
    [译]- 6-1 排列窗体上的控件(Laying Out Widgets on a Form)
    [转]
    [转]
    the thread has exited with code -1073741819
  • 原文地址:https://www.cnblogs.com/wpclw/p/6394695.html
Copyright © 2011-2022 走看看