note 72590 added to language.variables

From: Date: Thu, 25 Jan 2007 10:10:07 +0000
Subject: note 72590 added to language.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-122178@lists.php.net to get a copy of this message
Here's a pair of functions to encode/decode any string to be a valid php and javascript variable name. <?php function label_encode($txt) { // add Z to the begining to avoid that the resulting // label is a javascript keyword or it starts with a // number $txt = 'Z'.$txt; // encode as urlencoded data $txt = rawurlencode($txt); // replace illegal characters $illegal = array('%', '-', '.'); $ok = array('é', 'è', 'à'); $txt = str_replace($illegal,$ok, $txt); return $txt; } function label_decode($txt) { // replace illegal characters $illegal = array('%', '-', '.'); $ok = array('é', 'è', 'à'); $txt = str_replace($ok, $illegal, $txt); // unencode $txt = rawurldecode($txt); // remove the leading Z and return return substr($txt,1); } ?> ---- Server IP: 217.174.196.197 Probable Submitter: 83.192.185.171 ---- Manual Page -- http://www.php.net/manual/en/language.variables.php Edit -- https://master.php.net/note/edit/72590 Del: integrated -- https://master.php.net/note/delete/72590/integrated Del: useless -- https://master.php.net/note/delete/72590/useless Del: bad code -- https://master.php.net/note/delete/72590/bad+code Del: spam -- https://master.php.net/note/delete/72590/spam Del: non-english -- https://master.php.net/note/delete/72590/non-english Del: in docs -- https://master.php.net/note/delete/72590/in+docs Del: other reasons-- https://master.php.net/note/delete/72590 Reject -- https://master.php.net/note/reject/72590 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122178) next »