note 72590 deleted from language.variables by googleguy

From: Date: Mon, 11 Feb 2013 05:13:52 +0000
Subject: note 72590 deleted from language.variables by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193580@lists.php.net to get a copy of this message
Note Submitter: code at slater dot fr ---- 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); } ?>

« previous php.notes (#193580) next »