I personally use those functions:
class URL {
function sUrl() {
$_GET = explode('/',substr(getenv('REQUEST_URI'),1)); $_pth = PTH;
if(!empty($_pth)) {
$pth = explode('/',PTH);
for($i = 0; $i < count($_GET); $i++) if($_GET[$i] == $pth[$i]) unset($_GET[$i]);
array_splice($_GET,0,0);
} foreach($_GET as $k=>$v) $_GET[$k] = htmlspecialchars(addslashes($v));
}
}
function _parse($url) {
$url = substr($url,1,strlen($url));
$url = explode('&',$url);
foreach($url as $k => $v) {
$v = explode('=',$url[$k]);
$GET[$v[0]] = $v[1];
} return $GET;
}
function _url($name) { # parse url
$sign = '-';
$n = str_replace(' ',$sign,$name);
$n = strip_tags($n);
$n = str_replace("/",$sign,$n);
$n = str_replace('\"',$sign,$n);
$n = str_replace('.',$sign,$n);
$n = str_replace(',','',$n);
$n = str_replace('?','',$n);
$n = str_replace('!','',$n);
$n = str_replace('(','',$n);
$n = str_replace(')','',$n);
$n = str_replace(']','',$n);
$n = str_replace('[','',$n);
$n = str_replace(':','',$n);
$n = str_replace('&','',$n);
$n = str_replace('%','',$n);
$n = str_replace('#','',$n);
$n = str_replace('"','',$n);
$n = str_replace(' - ','',$n);
$n = str_replace('--','-',$n);
$n = str_replace('--','-',$n);
$n = str_replace('ndash;-','',$n);
$n = str_replace("'m",$sign.'am',$n);
$n = str_replace("'ve",$sign.'have',$n);
$n = str_replace("'s",$sign.'is',$n);
$n = str_replace("'",'',$n);
if(substr($n,-1) == '.') $n = substr($n,0,strlen($n)-1);
if(substr($n,-1) == $sign) $n = substr($n,0,strlen($n)-1);
if(substr($n,-1) == $sign) $n = substr($n,0,strlen($n)-1);
if(substr($n,-1) == $sign) $n = substr($n,0,strlen($n)-1);
return strtolower($n);
}
?>
And .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.path-of-power.com$ [NC]
RewriteRule ^(.*)$ http://path-of-power.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php
It allows me to use URLs like (
PHP PARSE URL, parse urls, parsing url):
http://path-of-power.com/extreme-tiredness-feeling-tired,1 where you can take from $_GET[0] as anything like: http://path-of-power.com/knowledge -> m/knowledge/index.php for example, test it.
Function, with usage of .htaccess file, gives: when user puts yourdomain.com/PARAM1/PARAM2 it auto gives in return (when assigned to $_GET = sURL();)
array (
'0' => 'PARAM1',
'1' => 'PARAM2',
)
or (when yourdomain.com/PARAM1/PARAM2, you get $_GET[0] // PARAM1 etc.). This function is very handful, because you always have the order and don't need to think on mod_rewrite rules. I use it on my all websites, use it too.
Function _url(); allows me to parse TITLES (parse url, like title of this article):
PHP PARSE URL, parse urls, parsing url -> http://path-of-power.com/
php-parse-url-parse-urls-parsing-url,148
Use them too, enjoy.
… Update 2011-08-06.
Here you've got: PHP ENGINE, multilingual, friendly urls, templates with modules (please check it). Thank you.
Edit
<AndyPSV> You've got in the article; first you do: $_GET = sURL();), and then you've got assigned all values,
you can print them by using: var_export($_GET); (remember to put .htaccess inside); then you need to
make some work to include your particular files you want to launch after entering X value in the
address bar
<Unknown> how to use it?
<Andreas M. Hahn> A standard-compliant, robust and performant PHP Class for URL handling and parsing according to RFC
3986 and RFC 3987 can be found here:http://andreas-hahn.com/en/parse-url – Andrzej Jeziorski 2 months ago · Reply