$urlPatterns = array(
'~'.preg_quote(BASE_DIR).'([^\.]+)\.php(\?([0-9a-zA-Z]+[^#"\']*))?~i',
);
ob_start();
#And in the global unloading script:
$pageContents = ob_get_contents();
ob_end_clean();
echo preg_replace_callback($urlPatterns,'urlRewriteCallback',$pageContents);
function urlRewriteCallback($match) {
$extra = '';
if ($match[3]) {
$params = explode('&', $match[3]);
if ($params[0] == '') array_shift($params);
foreach ($params as $param) {
$paramEx = explode('=', $param);
$extra .= $paramEx[0].'/'.$paramEx[1].'/';
}
}
return BASE_DIR.$match[1].'/'.$extra;
} 1 function urlRewriteCallback($match) {
$extra = '';
if ($match[3]) {
$params = explode('&', $match[3]);
if ($params[0] == '') array_shift($params);
foreach ($params as $param) {
$paramEx = explode('=', $param);
$extra .= $paramEx[0].'/'.$paramEx[1].'/';
}
}
return BASE_DIR.$match[1].'/'.$extra;
}
http://agachi.name/weblog/archives/2005/01/30/rewriting-dynamic-urls-into-friendly-urls.htm
No comments:
Post a Comment