PHP preg_match 没有返回正确的数组
PHP preg_match not returning correct array
所以我一直在阅读正则表达式,我在 youtube 上使用了一个很好的教程,解释得很好,所以我决定尝试使用 http://www.phpliveregex.com/,它在网站上效果很好,但在我的 php 代码。
所以我想要的是在一些 html 代码中找到获胜者的名字。我正在访问的这个网站只是为了测试目的,并且只在我的本地机器上 运行 ^^
<span style="width: 45%; float: left; text-align: left">
<div class="team" style="float: left; margin-right: 10%; background: url('http://cdn.csgolounge.com/img/teams/Cloud9.jpg?41')"></div>
<b>Cloud9 (win)</b><br><i>84%</i> </span>
所以我开始做的是整理一个单词和一个被包围的space和(win)。我这样做:
preg_match("<b>\w+\s\D\w\w\w\D</b>", $comment1, $comment2);
$comment1 是 html 代码。
然后我再次 preg_match 它只是为了检索获胜者的名字:
preg_match("[a-zA-Z]\w+", $comment2[0], $comment3);
然后我通过回显 comment2[0]
来结束
我已经在 phpliveregex 上试过了,效果很好。但是在我的网站上 comment2[0] 没有显示任何内容。
我正在将 html 代码插入到本地网站上的一个框中,然后传递给我的代码(我已经检查并确认这是有效的。
感谢您的帮助!
您必须在正则表达式周围添加分隔符:
preg_match("~<b>\w+\s\D\w\w\w\D</b>~", $comment1, $comment2);
preg_match("~[a-zA-Z]\w+~", $comment2[0], $comment3);
所以我一直在阅读正则表达式,我在 youtube 上使用了一个很好的教程,解释得很好,所以我决定尝试使用 http://www.phpliveregex.com/,它在网站上效果很好,但在我的 php 代码。
所以我想要的是在一些 html 代码中找到获胜者的名字。我正在访问的这个网站只是为了测试目的,并且只在我的本地机器上 运行 ^^
<span style="width: 45%; float: left; text-align: left">
<div class="team" style="float: left; margin-right: 10%; background: url('http://cdn.csgolounge.com/img/teams/Cloud9.jpg?41')"></div>
<b>Cloud9 (win)</b><br><i>84%</i> </span>
所以我开始做的是整理一个单词和一个被包围的space和(win)。我这样做:
preg_match("<b>\w+\s\D\w\w\w\D</b>", $comment1, $comment2);
$comment1 是 html 代码。
然后我再次 preg_match 它只是为了检索获胜者的名字:
preg_match("[a-zA-Z]\w+", $comment2[0], $comment3);
然后我通过回显 comment2[0]
来结束我已经在 phpliveregex 上试过了,效果很好。但是在我的网站上 comment2[0] 没有显示任何内容。
我正在将 html 代码插入到本地网站上的一个框中,然后传递给我的代码(我已经检查并确认这是有效的。
感谢您的帮助!
您必须在正则表达式周围添加分隔符:
preg_match("~<b>\w+\s\D\w\w\w\D</b>~", $comment1, $comment2);
preg_match("~[a-zA-Z]\w+~", $comment2[0], $comment3);