preg_match数组输出的问题 preg_match() 返回 pattern 所匹配的次数。要么是 0 次(没有匹配)或 1 次,因为 preg_match() 在第一次匹配之后将停止搜索。preg_match_all() 则相反,会一直搜索到 subject 的结尾处。如果出错 preg_match() 返回 FALSE。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php// \\2 是一个逆向引用的例子,其在 PCRE 中的含义是// 必须匹配正则表达式本身中第二组括号内的内容,本例中// 就是 ([\w]+)。因为字符串在双引号中,所以需要// 多加一个反斜线。$html = "<b>bold text</b><a href=howdy.html>click me</a>";preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches);for ($i=0; $i< count($matches[0]); $i++) { echo "matched: ".$matches[0][$i]."\n"; echo "part 1: ".$matches[1][$i]."\n"; echo "part 2: ".$matches[3][$i]."\n"; echo "part 3: ".$matches[4][$i]."\n\n";}?> <?php$str="<table><tr>·<a target='_blank' href='111' title=''>a</a></td></tr><tr><td>·<a target='_blank' href='222' title=''>b</a></td></tr><tr><td>·<a target='_blank' href='333' title=''>c</a></td></tr></table>";preg_match_all("/<a.*?href=\'(.*?)\'/",$str,$m);print_r($m[1]);?> PHP中嵌套HTML??? 有PHP后台,请问怎么在前台调用呢 运行php程序CPU使用率高 求php正则表达式 在整理smarttemplate例程手册时,遇到的一个问题,希望高手能来看一下 管理员请进! 容易的问题! 问问darkwing老兄,在php里如何重定向url PHP数组 怎么从指定位置开始查询? svn 问题求助 Apache和PHP配置成功,但PHP代码却不能被执行 RegisterNamespaces的作用?
// \\2 是一个逆向引用的例子,其在 PCRE 中的含义是
// 必须匹配正则表达式本身中第二组括号内的内容,本例中
// 就是 ([\w]+)。因为字符串在双引号中,所以需要
// 多加一个反斜线。
$html = "<b>bold text</b><a href=howdy.html>click me</a>";preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches);for ($i=0; $i< count($matches[0]); $i++) {
echo "matched: ".$matches[0][$i]."\n";
echo "part 1: ".$matches[1][$i]."\n";
echo "part 2: ".$matches[3][$i]."\n";
echo "part 3: ".$matches[4][$i]."\n\n";
}
?>
$str="<table>
<tr>·<a target='_blank' href='111' title=''>a</a></td>
</tr>
<tr>
<td>·<a target='_blank' href='222' title=''>b</a></td>
</tr>
<tr>
<td>·<a target='_blank' href='333' title=''>c</a></td>
</tr>
</table>";preg_match_all("/<a.*?href=\'(.*?)\'/",$str,$m);
print_r($m[1]);
?>