I need to encode a javascript function into a JSON object in PHP.
This:
$function = \"function(){}\";
$message = \"Hello\";
$json = array(
I wrote a small library that allows to do this. It's similar to Zend framworks's solution, but this library is much more lightweight as it uses the built-in json_encode function. It is also easier to use with external libraries, where json_encode is buried deeply in vendor code.
'cat',
'count' => 42,
'callback' => new Raw('function(a){alert(a);}')
];
?>