PHP – mb_split(多位元組拆分)函式


PHP 中的 mb_split() 函式用於使用正則表示式拆分多位元組字串。它以陣列格式返回結果。

語法

array mb_split($str_pattern, $str_string, int $limit=-1)

引數

mb_split() 接受以下三個引數 −

  • $str_pattern − 用於正則表示式的模式。

  • $str_string − 用於拆分字串。

  • $limit − 這是一個可選引數,用於指定限制元素。

返回值

mb_split 函式將以陣列的形式返回拆分元素結果。或者,它將在失敗時返回 False。

示例 1

<?php
   mb_internal_encoding("UTF-8");
   //mb_split function will split the string
   $string = mb_split(
      "[ ,]+", // Pattern
      "Welcome to the PHP Tutorial"); // string
   print_r($string);
?>

輸出

它將產生以下輸出 −

Array
(
   [0] => Welcome
   [1] => to
   [2] => the
   [3] => PHP
   [4] => Tutorial
)

更新於:2021-10-11

332 檢視

開啟你的 職業 生涯

透過完成課程來獲得認證

開始
廣告