note 106967 modified in function.urldecode by danbrown

From: Date: Tue, 03 Jan 2012 22:04:33 +0000
Subject: note 106967 modified in function.urldecode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185315@lists.php.net to get a copy of this message
Gets rid of 'amp;' in $_GET param names - so $_GET['amp;myVar'] becomes $_GET['myVar'] Made this because sometimes '&amp;' will wind up in the URL, as in: http://example.com/index.php?aaa=111&amp;myVar=222 Call this function at the top of your php page: unmake_amps(); <?php function unmake_amps() { foreach ($_GET as $g_param=>$g_value) { if (preg_match('/^amp\;(.*)$/i', $g_param)) { $g_paramNew = preg_replace('/^amp\;(.*)$/i', '$1', $g_param); unset($_GET[$g_param]); if ($g_paramNew != '') { // Only if $g_paramNew has a value, becaues sometimes '&amp;' winds up at the end of a url ($_GET['amp;']) $_GET[$g_paramNew] = $g_value; } } } } ?> Geek note: only for one-dimensional $_GET arrays - too lazy to make this a recursive function. --was-- // Gets rid of 'amp;' in $_GET param names - so $_GET['amp;myVar'] becomes $_GET['myVar'] // Made this because sometimes '&amp;' will wind up in the URL, as in: // http://sugarscript.com/index.php?aaa=111&amp;myVar=222 // Call this function at the top of your php page: unmake_amps(); function unmake_amps() { foreach ($_GET as $g_param=>$g_value) { if (preg_match('/^amp\;(.*)$/i', $g_param)) { $g_paramNew = preg_replace('/^amp\;(.*)$/i', '$1', $g_param); unset($_GET[$g_param]); if ($g_paramNew != '') { // Only if $g_paramNew has a value, becaues sometimes '&amp;' winds up at the end of a url ($_GET['amp;']) $_GET[$g_paramNew] = $g_value; } } } } Geek note: only for one-dimensional $_GET arrays - too lazy to make this a recursive function. http://php.net/manual/en/function.urldecode.php

« previous php.notes (#185315) next »