Skip to content

Instantly share code, notes, and snippets.

@YuzuRyo61
Last active February 15, 2017 08:32
Show Gist options
  • Save YuzuRyo61/dc0db90329e3167d4210eec75b8e4588 to your computer and use it in GitHub Desktop.
Save YuzuRyo61/dc0db90329e3167d4210eec75b8e4588 to your computer and use it in GitHub Desktop.
URLディレクトリ解析。解析後はArrayとして返される
#(Apache用)どのURLにアクセスしても、main.phpにアクセスできるようにする
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /main.php [L]
</IfModule>
<?php
// Create function :: 関数の作成
function urlArray($replacement){
$string = str_replace('/', ',', $replacement); // $replacementに代入されたURI変数(例: "/web/ja-jp/main")の'/'の部分を,に変換
$string = explode(',', $string); // ここでArray化
array_shift($string); // 0番目のArrayを削除(0番目のArrayは空白のため)
return $string;
}
?>
<?php
//URLパスの解析
print urlArray($_SERVER["REQUEST_URI"]);
// 結果(例: GET http://example.com/server/test/): Array ( [0] => server [1] => test )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment