Can I decode JSON containing PHP code? -


is possible have json string containing php code, , have string decoded?

for example, works should:

$array = ["page", "is-home", $_server["request_uri"] == "/"]; var_export($array);  // array ( //   0 => 'page', //   1 => 'is-home', //   2 => false, // ) 

this, not work:

$json = '["page", "is-home", $_server["request_uri"] == "/"]'; $array = json_decode($json); // returns null echo json_last_error_msg(); // syntax error 

the second example work if $_server["request_uri"] == "/" removed json string.

is there way parse string using json_decode, , if not, there alternative methods accomplish this?

many thanks!

update

the $_server["request_uri"] == "/" has parsed. trying extend blade templating can implement parsed functions such this:

@add-request('page', 'is-home', $_server["request_uri"] == '/') 

update #2

to try simplify matter, need turn string object.

$str = '["page", "is-home", $_server["request_uri"] == "/"]'; // obtained parsing top blade extension (not important how) 

from string need following array:

$array = ["page", "is-home", true / false ] 

keep in mind original string can contain theoretically php object 1 of json values.

i think you're on right track, instead of trying "simulate" decode putting single-quotes, why not (for proof of concept) first encode, 'echo' / 'print' value returns, , decode see returns.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -