<?php

/* Generate Permalink without page_id or other IDs */
$pos = strpos(get_permalink(),"?");
if ($pos !== FALSE) {
	$permalink = trim(substr(get_permalink(),0,$pos));
}
else {
	$permalink = get_permalink();
}

/* Generate Values to attach */
$pos = strpos($_SERVER[REQUEST_URI],"?");
if ($pos !== FALSE) {
	$URI = str_replace(array("%20","?"),array("xxxoooxxx","&"),trim(substr($_SERVER[REQUEST_URI],$pos,2048)));
}
else {
	$URI = '';
}

/* Generate finish URL */
$url = str_replace("xxxoooxxx","%20",preg_replace($arrayA,$arrayB,$permalink.$URI));

$pos = strpos($url, "&");
if ($pos !== false) { $url = substr_replace($url, "?", $pos, 1); }
if (strpos($url,"?") !== FALSE) { $url .= "&"; } else { $url .= "?"; }

if ($_GET['wct_debug'] == 'stefan') {
	echo "<table><tr><td>\$permalink</td><td>".$permalink."</td></tr>";
	echo "<tr><td>\$URI</td><td>".$URI."</td></tr>";
	echo "<tr><td>\$url</td><td>".$url."</td></tr>
<tr><td>\$url2</td><td>".$url2."</td></tr></table>";
}

?>