越简单越好!

PHP正则的一用法

发表于 2007-06-05 14:12 | 881次阅读 0次点赞   PHP

It is possible to name the subpattern with (?P<name>pattern) since PHP 4.3.3. Array with matches will contain the match indexed by the string alongside the match indexed by a number, then.

$pattern="/.*,(?P<name>.*?)像(?P<duty>.*?)吗?/";
$source="看起来,小陈像架构师吗?";
preg_match($pattern,$source,$matches);
echo($matches[1]."<br>");
echo($matches[2]."<br>");
echo($matches["name"]."<br>");
echo($matches["duty"]."<br>");


返回顶部 ^