PHP json_encode and javascript functions

后端 未结 9 1426
别跟我提以往
别跟我提以往 2020-12-06 04:28

I need to encode a javascript function into a JSON object in PHP.

This:

$function = \"function(){}\";
$message = \"Hello\";

$json = array(   
               


        
9条回答
  •  庸人自扰
    2020-12-06 04:43

    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);}')
        ];
    ?>
    
    
    

提交回复
热议问题