Here goes. I want to remove and re-arrange elements from an array after it completes the action. What the function does is convert a URL to remove the query info. (&'s, ='s and ?'s) Here's the code. It's a function called seo_go.
if ($seo_init !== true) {
function seo_go($SEO) {
$SEO = str_replace("&", "&", $SEO);
$result = "";
if (preg_match_all("'([^&=]+)=([^&=]+)'", $SEO, $matches)) {
foreach ($matches[0] as $index => $match) {
$result .= "/{$matches[1][$index]}/{$matches[2][$index]}";
}
}
return $result;
}
$QUERY_STRING = @explode("&", $QUERY_STRING) or $QUERY_STRING = array();
if ($_SERVER["PATH_INFO"] != "" ) {
$data = explode("/", $_SERVER["PATH_INFO"]);
reset($data);
while (list(,$name) = each($data)) {
if (in_array($name, array("start", "backups", "sub", "id", "cat"))) {
each($data);
} elseif ($name != "") {
list(,$value) = each($data);
$_GET[$name] = $value;
$HTTP_GET_VARS[$name] = $value;
$$name = $value;
$QUERY_STRING[] = "$name=$value";
}
}
}
foreach ($QUERY_STRING as $name => $value) {
$value = explode("=", $value);
if ($value[0] == "" or
$value[1] == "") {
unset($QUERY_STRING[$name]);
}
}
$QUERY_STRING = implode("&", $QUERY_STRING);
$_SERVER["QUERY_STRING"] = $QUERY_STRING;
$HTTP_SERVER_VARS["QUERY_STRING"] = $QUERY_STRING;
$seo_init = true;
}
#$PHP_SELF = explode(".php", $PHP_SELF); #settings I've blocked
#$PHP_SELF = $PHP_SELF[0] . ".php"; #settings I've blocked
The function is called elsewhere like this
$SEO=seo_go("sub=show&id=$news[0]&backups=$backups&start=$my_start&cat=$cat[$cats]");
$output = str_replace("[url]", "<a href=\"$PHP_SELF$SEO\">", $output);
What this does is take a url from this ugly query link www.domain.com/page.php?sub=show&id=ITEMNUMBER&backups=ITEMBACKUPNUMBER&start=$my_start&cat=CATEGORYNAME
to this glamourous link here
www.domain.com/page.php/sub/show/id/ITEMNUMBER/cat/CATEGORYNAME
I want to still execute through the array but remove the elements sub,show,id, and cat from the displayed URL so the url looks like
www.domain.com/page.php/ITEMNUMBER/CATEGORYNAME
Truthfully I want CATEGORYNAME displayed before ITEMNUMBER like this
www.domain.com/page.php/CATEGORYNAME/ITEMNUMBER
Either way but at this point I needed help.