$_SERVER
スーパーグローバルを使用して、要求された URI を検査できます。あなたの例で$_SERVER['REQUEST_URI']
は、次のように設定されます。
/news/10/
その後、その文字列から要求されたニュース ID を取得できます。
アップデート
// Use substr to ignore first forward slash
$request = explode('/', substr($_SERVER['REQUEST_URI'], 1));
$count = count($request);
// At this point, $request[0] should == 'news'
if($count > 1 && intval($request[1])) {
// The second part of the request is an integer that is not 0
} else {
if( $count == 1) {
// This is a request for '/news'
// The second part of the request is either not an integer or is 0
} else if($request[1] == 'latest') {
// Show latest news
} else if($request[1] == 'oldest') {
// Show oldest news
} else if($request[1] == 'most-read') {
// Show most read news
}
}
のマニュアルエントリを参照してください$_SERVER