PHP json_encode and javascript functions

后端 未结 9 1422
别跟我提以往
别跟我提以往 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条回答
  •  萌比男神i
    2020-12-06 05:03

    This function can also help:

    function jsonify($var){
    return str_ireplace(array("'function",'"function',"}'",'}"'),array("function",'function',"}",'}'),json_encode($var));
    }
    

    Taken from here: http://network.convergenceservices.in/forum/105-uknowva-development/4710-introducing-convhelperjsonify-in-uknowva-251.html#4710

提交回复
热议问题