PHP Regex在自定义添加的HTML标签之间查找文本 [英] PHP Regex find text between custom added HTML Tags
本文介绍了PHP Regex在自定义添加的HTML标签之间查找文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有他以下情况:
获得一个 HTML模板文件,该文件将用于mailing
.
Got an HTML template file that will be used for mailing
.
这是一个简化的示例:
<table>
<tr>
<td>Heading 1</td>
<td>heading 2</td>
</tr>
<PRODUCT_LIST>
<tr>
<td>Value 1</td>
<td>Value 2</td>
</tr>
</PRODUCT_LIST>
</table>
我要做的就是将HTML代码放入<PRODUCT_LIST>
内部,然后将其重复执行的次数与我在数组中获得的乘积相同.
All I need to do is to get the HTML code inside <PRODUCT_LIST>
and then repeat that code as many times as products I have on an array.
获取/替换此列表的正确的PHP Regex代码是什么?
谢谢!
推荐答案
假定<PRODUCT_LIST>
标签永远不会嵌套
Assuming <PRODUCT_LIST>
tags will never be nested
preg_match_all('/<PRODUCT_LIST>(.*?)<\/PRODUCT_LIST>/s', $html, $matches);
//HTML array in $matches[1]
print_r($matches[1]);
这篇关于PHP Regex在自定义添加的HTML标签之间查找文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文