zoukankan      html  css  js  c++  java
  • PHP strrpos strpos strstr strrchr 区别

    1. strstr 

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

    $needle 为字符串,如果不是字符串,那么转化为整型,使用该整型对应的字符。

    返回 该字符(串)首次出现到字符串尾部分, 包括该字符(串)。

    2.  strrchr

    string strrchr ( string $haystack , mixed $needle )

    $needle为字符, 如果是字符串,使用字符串的首字符作为匹配字符(区别于其他几个函数对字符串情况的处理), 如果不是字符也不是字符串,则转化为整型,使用该整型对应的字符。

    返回该字符最后一次出现到字符串尾部分, 包括该字符。

    3. strpos

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

    返回某个字符串第一次出现的位置, 如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符的顺序值。

    4. strrpos

    返回某个字符最后一次出现的位置, 如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符的顺序值。

    <?php
    
    $str = 'sailrancho@qq.com';
    
    echo strstr($str,'qq.'); // 返回 qq.com
    echo "
    ";
    echo strrchr($str, 'ch'); // 返回 com 注意返回不是cho@qq.com
    echo "
    ";
    echo strpos($str, 'c'); //返回 7 
    echo "
    ";
    echo strrpos($str, 'c'); // 返回14
  • 相关阅读:
    [POJ][3072][Robot]
    [HDU][4021][24 Puzzle]
    [POJ][1228][Grandpa's Estate]
    [POJ][3662][Telephone Lines]
    [HDU][4007][Dave]
    [POJ] [1264] [SCUD Busters]
    ASP.NET中的COOKIE
    分享至...(源码)
    php获取图片并输出
    VNC 服务器/本地复制粘贴实现命令
  • 原文地址:https://www.cnblogs.com/sailrancho/p/3416753.html
Copyright © 2011-2022 走看看