zoukankan      html  css  js  c++  java
  • PHP字符串函数 strstr()使用详解

    定义

    strstr - 按分隔符截取字符串

    语法

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

    返回 haystack 字符串从 needle 第一次出现的位置开始到 haystack 结尾的字符串。包括needle。
    不存在则返回false。

    如果仅仅想确定 needle 是否存在于 haystack 中,可以使用速度更快、耗费内存更少的 strpos() 函数。

    before_needle 如果为true,则返回 needle 在 haystack 中的位置之前的部分,不包括needle。

    示例

    <?php
    $email  = 'name@example.com';
    $domain = strstr($email, '@');
    echo $domain; // @example.com
    
    $user = strstr($email, '@', true); // 从 PHP 5.3.0 起
    echo $user; // name,不包含@
    ?>
    
  • 相关阅读:
    web http协议
    swoole udp
    swoole线程和进程
    SVN中trunk,branches,tags用法详解
    mysql外键使用和事物使用
    xml
    dedecms开启报错
    Django CBV方法装饰器
    Django Cookie和Session
    ORM基础5
  • 原文地址:https://www.cnblogs.com/jiaoran/p/12767326.html
Copyright © 2011-2022 走看看