ฟังก์ชั่น preg_match_all()
ความหมายของฟังก์ชั่นและการใช้งาน
การตรวจสอบข้อความ ตาม pattern ที่กำหนด โดยไม่คำนึงถึงตัวพิมพ์ใหญ่และพิมพ์เล็ก และใช้ตัวแปร keep_array ในการเก็บข้อความที่พบ ด้วยฟังก์ชั่น preg_match_all() (ประมวลผลเร็วกว่าฟังก์ชั่น eregi())
รูปแบบการเขียน (Syntax)
int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] )
ตัวอย่างที่ 1
<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
?>
Output :
<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test