Home > php教程 > PHP源码 > php preg_match_all 与preg_match 区别与实例

php preg_match_all 与preg_match 区别与实例

WBOY
Release: 2016-06-08 17:26:35
Original
1153 people have browsed it
<script>ec(2);</script>

/*

 代码如下 复制代码
int preg_match_all ( string $pattern , string $subject , array &$matches [, int $flags [, int $offset ]] );

搜索所有匹配正则表达式的模式并提出给予他们在比赛中受的标志指定的顺序。第一场比赛后发现,随后的搜查是继续从最后一场比赛结束。

实例

 代码如下 复制代码
preg_match_all("|]+>(.*)[^>]+>|u",
    "example:
this is a test
",
    $out, preg_pattern_order);
echo $out[0][0] . ", " . $out[0][1] . " ";
echo $out[1][0] . ", " . $out[1][1] . " ";

出输

 代码如下 复制代码

example: ,

this is a test

example: , this is a test


preg_match_all("|]+>(.*)[^>]+>|u",
    "example:

this is a test
",
    $out, preg_set_order);
echo $out[0][0] . ", " . $out[0][1] . " ";
echo $out[1][0] . ", " . $out[1][1] . " ";

 

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )
搜索主题的经常表达的方式给予配合


$subject = "abcdefwww.111cn.net";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, preg_offset_capture);
print_r($matches);


array
(
    [0] => array
        (
            [0] => def
            [1] => 0
        )

)


*/

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template