Skip to content
Advertisement

PHP json_encode encode a function

How to encode a Javascript function in PHP? I want to encode the callback function with array

$options = array(
'title' => 'Title',
'fnCallback' => someCallback);

equivalent ini Javascript:

var options = {
'title': 'Title',
'fnCallback': someCallback };

I know my PHP code is wrong, how can I fix it?

Advertisement

Answer

Viola i solved my problem with Zend_JSON encoder

 $options = array(
     'title' => 'Title',
     'fnCallback' => new Zend_Json_Expr('someCallback')
 );      

 Zend_Json::encode(
     $options,
     false,
     array('enableJsonExprFinder' => true));
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement