加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

php进修条记之mb_strstr的根基行使

发布时间:2021-03-31 08:13:36 所属栏目:编程 来源:网络整理
导读:媒介 本文首要先容了关于php之mb_strstr根基行使的相干内容,分享出来供各人参考进修,下面话不多说了,来一路看看具体的先容吧。 mb_strstr (PHP 5 >= 5.2.0,PHP 7) mb_strstr — Finds first occurrence of a string within another 查找字符串在另一个

媒介

本文首要先容了关于php之mb_strstr根基行使的相干内容,分享出来供各人参考进修,下面话不多说了,来一路看看具体的先容吧。

mb_strstr

  • (PHP 5 >= 5.2.0,PHP 7)
  • mb_strstr — Finds first occurrence of a string within another
  • 查找字符串在另一个字符串里的初次呈现

Description

//mb_strstr() finds the first occurrence of needle in haystack and returns the portion of haystack. If needle is not found,it returns FALSE.
//mb_strstr() 查找了 needle 在 haystack 中初次的呈现并返回 haystack 的一部门。 假如 needle 没有找到,它将返回 FALSE。

Parameters

haystack

  • The string from which to get the first occurrence of needle
  • 要获取 needle 初次呈现的字符串。

needle

  • The string to find in haystack
  • 在 haystack 中查找这个字符串。

before_needle

  • Determines which portion of haystack this function returns. If set to TRUE,it returns all of haystack from the beginning to the first occurrence of needle (excluding needle). If set to FALSE,it returns all of haystack from the first occurrence of needle to the end (including needle).
  • 抉择这个函数返回 haystack 的哪一部门。 假如配置为 TRUE,它返回 haystack 中从开始到 needle 呈现位置的全部字符(不包罗 needle)。 假如配置为 FALSE,它返回 haystack 中 needle 呈现位置到最后的全部字符(包罗了 needle)。

encoding

  • Character encoding name to use. If it is omitted,internal character encoding is used.
  • 要行使的字符编码名称。 假如省略该参数,将行使内部字符编码。

Return Values

  • Returns the portion of haystack,or FALSE if needle is not found.
  • 返回 haystack 的一部门,可能 needle 没找到则返回 FALSE。

Examples

// If set to true,it returns all of haystack from the beginning to the first occurrence of needle.
$strstr = mb_strstr( "hello china","ll",true );
echo $strstr . PHP_EOL; //he

//* If set to false,it returns all of haystack from the first occurrence of needle to the end,$strstr = mb_strstr( "hello china",false );
echo $strstr . PHP_EOL;//llo china

//hello china
echo mb_strstr( "hello china",true ) . mb_strstr( "hello china",false ) . PHP_EOL;

$strstr = mb_strstr( "hello China,hello PHP",true );
echo $strstr . PHP_EOL; //he

$strstr = mb_strstr( "hello China,false );
echo $strstr . PHP_EOL; //llo China,hello PHP

$strstr = mb_strstr( "PHP是天下上最好的说话😄","最好",true );
echo $strstr.PHP_EOL; //PHP是天下上
$strstr = mb_strstr( "PHP是天下上最好的说话😄",false );
echo $strstr.PHP_EOL; //最好的说话😄

总结

以上就是这篇文章的所有内容了,但愿本文的内容对各人的进修可能事变具有必然的参考进修代价,假若有疑问各人可以留言交换,感谢各人对编程之家的支持。

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读