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中如何获得客户端IP地址 php 服务器部署网站 我画的网站结构图,无偿奉献给大家 PHP 读取大文件尾部20行 ffmpeg 转换视频的问题,请指点 50分求人帮忙,在线等待 editplus .key文件怎么制作?非.mac键盘纪录文件 xml如何解析一个变量,不是文件 我用永久联结把数据库锁定后,再解锁却进不了数据库了,这是为什么? 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]);
?>