:
$url = "stackoverflow.com/index.php/section1/article22";
$myArray = array_slice( explode('/', $url), 2 );
echo "section: ". $myArray[0] ."<br /> article: ". $myArray[1]."<br />";
if(isset($myArray[0])) {
$section = $myArray[0];
} else {
$section = "";
}
if(isset($myArray[1])) {
$article = $myArray[1];
} else {
$article = "";
}
switch(strtolower($section)) {
default:
echo "home";
break;
case 'section1':
echo "function for find and show my article: ". $article;
break;
}
, db, select, id, Article
index.php, :
.htaccess
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond $0 !^(index\.php|css|js|img)
RewriteRule ^(.*)$ index.php [L]
index.php:
$url = addslashes($_SERVER['REQUEST_URI']);
$myArray = array_slice( explode('/', $url), 1 );