php中mb_strstr的基本使用方法

小云云
發布: 2023-03-19 21:22:01
原創
1523 人瀏覽過

本文主要介紹給大家關於php學習筆記之mb_strstr的基本使用,文中透過範例程式碼介紹的非常詳細,對大家的學習或工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧,希望能幫助大家。

mb_strstr

  • (PHP 5 >= 5.2.0, PHP 7)

  • mb_strstr — Finds first occurrence of a string within another

  • 查找字串在另一個字串裡的首次出現

Description

#
string mb_strstr ( 
 string $haystack , 
 string $needle [, 
 bool $before_needle = false [, 
 string $encoding =mb_internal_encoding() ]] 
 )

//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#########<?php
/** * 由 PhpStorm 建立。
 * 用戶: 張榮祥
 * 日期:2018/2/1
 * 時間:下午10:27
 */

//* * 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", "ll", false );
echo $strstr . PHP_EOL;//llo china

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

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

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

$strstr = mb_strstr( "PHP是全世界最好的語言
登入後複製

以上是php中mb_strstr的基本使用方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!