PHP - parsing javascript array using a preg_match() -


i have problem parsing html page. there variable in javascript need , put json format.

<script>   var variable1 = "foo";   var variable2 = "boo";   var multiplearray = [             {"var1":"1",              "var2": [{                  "var21":"extra lge",                  "var22":"45923090470",                  "var23": {"key1":"value1",                            "key2":"value"}                  }],                  ...etc...              }] </script> 

is there easy way, how var multiplearray , keys , values ? used preg_match()

preg_match("'var multiplearray = [\{.*?\}]'", $source, $matches ); 

but returns $matches empty array().

what doing wrong? experence reg.ex. on level 0 :(

i'll glad :) thank :)

with th following pattern should array without var multiplearray identifier.

preg_match('/\[(\{(.*)\})\]/', $source, $matches ); 

now key value pairs have parse it. or if want have quick, dirty , evil win following:

you use str_replace() replace every ':' '=>', '[{' '[', '}]' ']', '{' '[', '}' ']'.

with result-string ($result) following:

$result_array = null; eval('$result_array = '.$result); 

now $result_array contains array.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -