note 101497 deleted from function.json-encode by tularis
| From: | tularis@php.net | Date: | Thu, 04 Feb 2016 08:32:17 +0000 |
| Subject: | note 101497 deleted from function.json-encode by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-204852@lists.php.net to get a copy of this message | ||
Note Submitter: rdheijer at reestyle dot net
----
You may run into trouble when you need to call functions. In my case I had to fire a function based
on a button pressed in the flexigrid javascript component.
My solution in the project was:
<?php
$jsonify = array('onpress'=>'functionName');
// The part between braces in the regex is somewhat rough
// but it will do the job. Afterall, you don't want this to be
// used by a visitor :)
$regex = '/"onpress":"([\w\-\.]+)"/i';
$replace = '"onpress":$1';
$jsonified = preg_replace($regex, $replace, json_encode($jsonify));
?>
But you can extend this for your own needs. By altering the regex and replace vars:
<?php
$replace = '"$1":$2';
$regex =
'/"(onpress|onclick|onmouseover|onmouseout)":"([\w_\-\.]+)"/i';
?>
Unfortunately you have to specify each call reference, but it does give you full control over what
to and what not to.