首页 > php代码 > php preg_match_all 与preg_match 区别与实例

php preg_match_all 与preg_match 区别与实例

/*

int preg_match_all ( string $pattern , string $subject , array &$matches [, int $flags [, int $offset ]] );

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

实例

<?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] . " ";
echo $out[1][0] . ", " . $out[1][1] . " ";
//输出


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

example: , this is a test


<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|u",
    "<b>example: </b><div align=\"left\">this is a test</div>",
    $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.phprm.com";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, preg_offset_capture);
print_r($matches);


array

(

    [0] => array

        (

            [0] => def

            [1] => 0

        )

)


本文地址:http://www.phprm.com/code/33670.html

转载随意,但请附上文章地址:-)

标签:none

发表留言