问题
Recently I asked a question regarding preg_match_all
with php, and i got the perfect solution as expected but now I have some different scenario
here is my string :
$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>';
My Code :
preg_match_all('/{{ type="(.+?)" }}/', $html, $matches, PREG_SET_ORDER);
echo "<pre>";
print_r($matches);
foreach ($matches as $val) {
echo $val[1];
echo "<br/>";
}
?>
Result i am getting :
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
How can i get the values for slider
and pagename
variable written in {{
and }}
in the string ?
回答1:
Here:
/{{ type=\"(.+)\"\s+pagename=\"(.+)\" }}/i
In action: https://regex101.com/r/tX9vD3/1
来源:https://stackoverflow.com/questions/39286071/preg-match-all-match-multiple-strings-and-get-the-values-written-in-double-quote