/*
Name: RemoveUrlParam.php3
AUTHOR: Ulysses J Ludwig
AUTHOR URL: www.ujludwig.com
DATE CREATED: 1.24.00
LAST MODIFIED: 3.06.00 (6:30 PM)
INCLUDED BY: Lib.inc
CALLED BY: Anywhere
PREREQUISITES: None
COMMENTS: The script removes a url parameter from a url string. Please
note: I am sure there is a way to shorten this script, but then no one
would be able to read it but me. Ergo it is longer for a reason. Also,
if the url passed in is already encoded, then the parameter should also
be encoded first
EXAMPLE: Fn_remove_url_param("$Url&ParamVariable","param_name");
*/
/////////////////////////////////////////////////////////////////////////////////////////
//////////// (REMOVE URL PARAMETER) CALLED FROM ANYWHERE /////////////////////////////
function Fn_remove_url_param($In_url, $In_param_name)
{
trim($In_url);
$qm = chr(63); //
Creates a question mark
$L_qm_pos = strpos($In_url, $qm) + 1; // Creates a variable that holds the
position of the question mark (it may be 0 if there is no question mark)
// When searching for the parameter, make sure that it is
// proceeded by an & or ? and followed by an = sign
$L_search_string = ("?" . $In_param_name . "=");
$L_param_pos = strpos($In_url,$L_search_string);
if (!empty($L_param_pos))
{
// Parameter is led by ?... preserve the question mark
$L_param_pos++;
}
else
{
$L_search_string = ("&" . $In_param_name . "=");
$L_param_pos = strpos($In_url, $L_search_string);
}
if (!empty($L_param_pos))
{
// The parameter exists in the param string so remove it
// Find the end of the param name value pair
for ($i = $L_param_pos + 1; $i <= strlen($In_url); $i++)
{
$L_character = (substr($In_url, $i, 1));
if ($L_character == " " or $L_character == "&")
{
$i ++;
break;
}
}
$L_pos = strpos($In_url, "&&");
if (!empty($L_pos))
{
// Remove one of the &s
$In_url = substr($In_url, 0,$L_pos + 1) .
substr($In_url, $L_pos + 2, strlen($In_url));
}
if (strpos($In_url, "?") > 0 and (strpos($In_url, "?") == strlen($L_url)))
{
// Then the question mark that is trailing has no parameters, remove it
$In_url = substr($In_url, 0, strlen($L_url - 1));
}