Home >Backend Development >PHP Tutorial >函式:preg_match_all()_PHP

函式:preg_match_all()_PHP

WBOY
WBOYOriginal
2016-06-01 12:39:20802browse

函式:preg_match_all()

--------------------------------------------------------------------------------



Perl 相容语法函式库





preg_match_all
字串整体比对剖析。



语法
: int preg_match_all(string pattern, string subject, array matches, int [order]);



传回值: 整数



函式种类
: 资料处理









内容说明





本函式以 pattern 的规则来整体剖析比对字串 subject。比对结果传回的值放在阵列参数 matches 之中
并依顺序值 order 排序。参数 order 的值有 PREG_PATTERN_ORDER 及 PREG_SET_ORDER 二种。若没有 order 值则系统自动以 PREG_PATTERN_ORDER 代入 order 值中。传回值为合乎比对结果的数目若没有或错误则传回 false 值。









使用范例





PREG_PATTERN_ORDER 的例子




preg_match_all
("|]+>(.*)[^>]+>|U", "

a test
", $out, PREG_PATTERN_ORDER);

print $out[0][0].", ".$out[0][1]."\n";

print $out[1][0].", ".$out[1][1]."\n"

?>       



传回值为



b>example: /b>, div align=left>this is a test/div>

example: , this is a test









PREG_SET_ORDER 的例子




preg_match_all
("|]+>(.*)[^>]+>|U", "
a test
"
, $out, PREG_SET_ORDER);

print $out[0][0].", ".$out[0][1]."\n";

print $out[1][0].", ".$out[1][1]."\n"

?>



传回值为          



b>example: /b>, example:

div align=left>this is a test/div>, this is a test


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn