note 101497 added to function.json-encode

From: Date: Tue, 21 Dec 2010 10:11:53 +0000
Subject: note 101497 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-175089@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'; $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. ---- Server IP: 69.147.83.197 Probable Submitter: 77.165.226.116 ---- Manual Page -- http://www.php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/101497 Del: integrated -- https://master.php.net/note/delete/101497/integrated Del: useless -- https://master.php.net/note/delete/101497/useless Del: bad code -- https://master.php.net/note/delete/101497/bad+code Del: spam -- https://master.php.net/note/delete/101497/spam Del: non-english -- https://master.php.net/note/delete/101497/non-english Del: in docs -- https://master.php.net/note/delete/101497/in+docs Del: other reasons-- https://master.php.net/note/delete/101497 Reject -- https://master.php.net/note/reject/101497 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175089) next »