Parsing javascript arrays in PHP -


i can't seem figure out how js array php.

what have work looks this:

var arrlow = [ { "e": "495864", "rank": "8678591", "rankmove": "<p><img src='up.php?ustyle=144'> 495864" }, { "e": "104956", "rank": "-", "rankmove": "<p><img src='up.php?ustyle=145'> down 1" }, { "e": "0", "rank": "0", "rankmove": "<p><img src='up.php?ustyle=975'> new" } ] 

json_decode , others return null, google returns strange way use serialize() http post js-understanding browser can't work here

does have clue how :x

==========================================================================

edit: guys! didnt know easy

<?php  $json = file_get_contents('24d29b1c099a719zr8f32ce219489cee.js'); $json = str_replace('var arrlow = ','' ,$json); $data = json_decode($json); echo $data[0]->e; ?> 

you can use json_decode() this. trick leave away var arrlow = part (so array left). can assign value php variable $arrlowlike this:

$js = '[ {"e" : "495864", ...'; $arrlow = json_decode($js); 

a quick'n'dirty hack remove beginning use strstr() function.

$js = strstr('var arrlow = [ {..', '['); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -