如何解析HTML/XML并从中提取信息?
我的一些HTML文件包含如下字符串:
{foreach $any_kind_of_charaters}
Any kind of string including "\n\r" and spaces here
{/foreach}
Run Code Online (Sandbox Code Playgroud)
我想申请PHP's preg_match_all他们,并希望返回一个array像下面打印的好
Array
(
[0] => {foreach $any_kind_of_charaters}
Any kind of string including "\n\r" and spaces here
{/foreach}
[1] => any_kind_of_charaters
[2] => Any kind of string including "\n\r" and spaces here
)
Run Code Online (Sandbox Code Playgroud)
这个REGEX:/\{foreach\s+\$(.*)\}\s+(.*)\s+\{\/foreach\}/对我来说还可以,
但是当我在{foreach}{/foreach}标签之间添加新行(\n)时它会失败.
非常感谢您的帮助,谢谢.
使用"S"修改器后的阵列
Array
(
[0] => {foreach $any_kind_of_charaters}
Any kind of string including "\n\r" and spaces here
{/foreach}
[1] => any_kind_of_charaters}
Any kind of …Run Code Online (Sandbox Code Playgroud)