正在使用在线但正在使用PHP的正则表达式没有

时间:2017-02-12 11:41:49

标签: php regex

我尝试将此文字与正则表达式匹配

<h2><!-- mp_trans_rt_start id="1" args="as" 5 -->adidas Energy Cloud Mens Trainers<!-- mp_trans_rt_end 5 --></h2> <!-- mp_trans_mt_start 208 --><!-- mp_trans_remove_start="DE,FR,AT" -->

我使用在线测试仪,它与

一起使用
/(<!--.+?-->)/g

/(<!--.*?-->)/g

但是当我在PHP中使用它时它返回空数组

preg_match_all('/(<!--.+?-->)/', $description, $matcheseds);

这是我的代码副本的剪切部分,并在CLI中运行它 http://pastebin.com/pvnRb8Z1

regex在定义之后位于顶部

1 个答案:

答案 0 :(得分:0)

通过查看您的代码,我没有看到从网页加载的HTML是实体编码的任何地方(即<和>转换为<>),所以这是为什么正则表达式永远不会匹配。

只需将正则表达式更改为此选项即可使用未编码的字符查找原始HTML注释:

preg_match_all('/(<!--.+?-->)/', $description, $matcheseds);