Last active
February 15, 2017 08:32
-
-
Save YuzuRyo61/dc0db90329e3167d4210eec75b8e4588 to your computer and use it in GitHub Desktop.
URLディレクトリ解析。解析後はArrayとして返される
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#(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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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