note 101497 modified in function.json-encode by danbrown

From: Date: Tue, 21 Dec 2010 15:01:56 +0000
Subject: note 101497 modified in function.json-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175097@lists.php.net to get a copy of this message
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. --was-- 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'; $reqex = '/"(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. http://php.net/manual/en/function.json-encode.php

« previous php.notes (#175097) next »