最近I asked a question关于preg_match_all
与php,我得到了完美的解决方案,但现在我有一些不同的场景
这是我的字符串:
$html = '<p> This is my Home Page.</p><p><span style="line-height: 1.42857;">
{{ type="slider" pagename="slider-1" }}
{{ type="banner" pagename="banner-1" }}
{{ type="testimonial" pagename="testimonial-1" }}
</span></p><p> </p>';
我的代码:
preg_match_all('/{{ type="(.+?)" }}/', $html, $matches, PREG_SET_ORDER);
echo "<pre>";
print_r($matches);
foreach ($matches as $val) {
echo $val[1];
echo "<br/>";
}
?>
我得到的结果:
Array
(
[0] => Array
(
[0] => {{ type="slider" pagename="slider-1" }}
[1] => slider" pagename="slider-1
)
[1] => Array
(
[0] => {{ type="banner" pagename="banner-1" }}
[1] => banner" pagename="banner-1
)
[2] => Array
(
[0] => {{ type="testimonial" pagename="testimonial-1" }}
[1] => testimonial" pagename="testimonial-1
)
)
slider" pagename="slider-1
banner" pagename="banner-1
testimonial" pagename="testimonial-1
如何获取字符串中slider
和pagename
中写入的{{
和}}
变量的值?
答案 0 :(得分:2)