i'm trying retrieve all matches receiving one
here string
$html = '<p> home page.</p><p><span style="line-height: 1.42857;">{{ type="slider" }} </span></p><p> </p>';
if see string contain {{ type="slider" }}
, if write string once getting expected result, if write multiple times in html sting {{ type="slider" }}
{{ type="banned" }}
{{ type="testimonial" }}
$html = '<p> home page.</p><p><span style="line-height: 1.42857;">{{ type="slider" }} {{ type="banner" }} {{ type="testimonial" }} </span></p><p> </p>';
and try values within string {{ type=" ???? " }}
shows weird result
i using below code .
preg_match_all('/{{ type=\"(.+)\" }}/', $html, $matches, preg_set_order); echo "<pre>"; print_r($matches); foreach ($matches $val) { echo "matched: ". $val[0] . "<br/>"; echo "my value" . $val[1] . "<br/>"; }
current result :
array ( [0] => array ( [0] => {{ type="slider" }} {{ type="banner" }} {{ type="testimonial" }} [1] => slider" }} {{ type="banner" }} {{ type="testimonial ) ) matched: {{ type="slider" }} {{ type="banner" }} {{ type="testimonial" }} value : slider" }} {{ type="banner" }} {{ type="testimonial
i expecting result in array values written between {{ type="
, " }}
with {{ type="slider" }}
getting result perfect.
array ( [0] => array ( [0] => {{ type="slider" }} [1] => slider ) ) matched: {{ type="slider" }} value : slider
any idea ?
sorry bad english.
you need make regex match non-greedy adding either ?
:
preg_match_all('/{{ type=\"(.+?)\" }}/', $html, $matches, preg_set_order);
or u
modifier:
preg_match_all('/{{ type=\"(.+)\" }}/u', $html, $matches, preg_set_order);
Comments
Post a Comment