regex - php preg_match_all key value pair -
[[[begin]]] [[[mapid]]]1994 [[[price]]]15000 [[[cate1]]]top [[[maker]]] [[[origi]]] [[[modig]]]n [[[ftend]]] [[[begin]]] [[[mapid]]]1994 [[[price]]]15000 [[[cate1]]]top2 [[[maker]]] [[[origi]]] [[[modig]]]n [[[ftend]]] ...
here multiple info template.
is time, want key-value pair result, utilize preg_match
$pattern .= "(?p<mapid>[[[pname]]](.*?))"; $pattern .= "[[[price]]](.*?)"; ...
is result
[mapid] => [0] => [[[mapid]]]175741
but, want result below,
[mapid] => [0] => 175741
additionally, when want cost not exist,
$pattern .= "(?p<mapid>[[[pname]]](.*?))"; $pattern .= "?([[[price]]](.*?))";
not working...
what should results want?
(?p<mapid>(?<=\[\[\[price\]\]\]).*)
try this.see demo.
http://regex101.com/r/dz1vt6/47
regex parsing preg-match
No comments:
Post a Comment