Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP – ฟังก์ชัน mb_split (Multibyte Split)

ฟังก์ชัน mb_split() ใน PHP ใช้ split multibyte string ด้วย regular expressions คืนค่าผลลัพธ์ในรูป array

Syntax

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

Parameters

mb_split() รับ 3 พารามิเตอร์:

  • $str_pattern – ใช้สำหรับ regular expression pattern

  • $str_string – string ที่จะ split

  • $limit – optional parameter ระบุ limit elements

Return Values

mb_split คืนค่า split elements เป็น array หรือ False หากล้มเหลว

Example 1

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

Output

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