mardi 24 février 2015

Regular expression entire string matched not components

I am trying to scan a PHP file for variable definitions e.g. $test="1"; and return both the variable name and the value, here is what I tried so far:



preg_match_all('/\$(.*)="(.*)";/', $content, $out);


This works fine when I have a lot of variables defined over separate lines, e.g:



$test1="1";
$test2="2";
$test3="3";


But when the variables are defined one next to another, then my match simply returns one giant string, e.g.



$test1="1";$test2="2";$test3="3";


I think this is because it is being interpreted as:



$test1="[content]";
Where [content] = 1";$test2="2";$test3="3


Is there any workaround to this? I need it to FORCE essentially a new match as soon as it encounters "; not simply at the end.


Aucun commentaire:

Enregistrer un commentaire