<?php
/*************************************************
friendlyurls.php - a utility class for making urls nicer together with apache's forcetype directive
home page: www.samscripts.com/scripts/friendlyurls
support: support.samscripts.com/index.php
licence: freeware / optionally giftware ( www.samscripts.com/donate.php )
author: Sam Yapp
date: 8th September 2002
documentation and examples at www.samscripts.com
*************************************************/
class friendlyurls{
function friendlyurls($search = "", $replace = "", $noduplicates = true, $noquerystring = true){
global $HTTP_SERVER_VARS;
$script = $HTTP_SERVER_VARS["SCRIPT_NAME"];
$decoded = urldecode($HTTP_SERVER_VARS["REQUEST_URI"]);
if( $noquerystring ) $decoded = preg_replace("/\?.*/", "", $decoded);
if( ( is_array($search) && count($search) != 0 ) || $search != "" ) $decoded = preg_replace($search, $replace, $decoded);
$uri = preg_replace("!^$script!i", "", $decoded);
$arguments = preg_split("/\//",$uri,-1, PREG_SPLIT_NO_EMPTY);
$arguments_slashed = preg_split("/\//",addslashes($uri), -1, PREG_SPLIT_NO_EMPTY);
$argcount = count($arguments);
$this->argument_count = 0;
if( $noduplicates ){
$this->arguments = array();
$this->arguments_slashed = array();
for( $i = 0; $i < $argcount; $i++){
if( !in_array($arguments[$i], $this->arguments)){
$this->arguments[$this->argument_count] = $arguments[$i];
$this->arguments_slashed[$this->argument_count] = $arguments_slashed[$i];
$this->argument_count++;
}
}
}else{
$this->argument_count = $argcount;
$this->arguments = &$arguments;
$this->arguments_slashed = &$arguments_slashed;
}
}
}
?>