相关疑难解决方法(0)

2071
推荐指数
28
解决办法
40万
查看次数

PHP:简单的正则表达式问题

我的一些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)

php regex preg-match-all

0
推荐指数
1
解决办法
152
查看次数

标签 统计

php ×2

html-parsing ×1

parsing ×1

preg-match-all ×1

regex ×1

xml ×1

xml-parsing ×1