regex - PHP Regexp for getting variable="value" from string -
regex - PHP Regexp for getting variable="value" from string -
i have m3u file contain lines example:
#extinf:0 $extfilter="viva" group-title="variedades" tvg-logo="logo/viva.png" tvg-name="viva"
i run in php no success:
preg_match('/([a-z0-9\-_]+)=\"([a-z0-9\-_\s.]+)\"\s+/i',$str,$matches)
i want get:
$matches[0] = $extfilter $matches[1] = viva $matches[2] = group-title $matches[3] = variedades $matches[4] = tvg-logo $matches[5] = logo/viva.png $matches[6] = tvg-name $matches[7] = viva
i seek regexp tools (like this).
thank u.
use preg_match_all
perform multiple matches:
preg_match_all('/([\w-]+)="([\w-\s.\/]+)"/i',$str,$matches, preg_set_order);
it returns results 2-dimensional array -- 1 dimension match, dimension capture groups within matches. them single array in desired result, utilize loop:
$results = array(); foreach ($matches $match) { array_push($results, $match[1], $match[2]); } print_r($results);
prints:
array ( [0] => extfilter [1] => viva [2] => group-title [3] => variedades [4] => tvg-logo [5] => logo/viva.png [6] => tvg-name [7] => viva )
i simplified regexp using \w
in place of a-z0-9_
. added /
sec character set, logo/viva.png
match. got rid of \s+
@ end, because prevented lastly variable assignment working.
php regex preg-match m3u
Comments
Post a Comment