私は私のURLを持っています:
http://domain/fotografo/admin/gallery_bg.php
そして、私はURLの最後の部分が欲しい:
gallery_bg.php
しかし、私は静的にリンクしたくありません。つまり、訪問したページごとに、URLの最後の部分を取得したいのです
ベースネーム関数を使用する
echo basename("http://domain/fotografo/admin/gallery_bg.php");
同じページの場合:
echo $_SERVER["REQUEST_URI"];
or
echo $_SERVER["SCRIPT_NAME"];
or
echo $_SERVER["PHP_SELF"];
いずれの場合も、バック スラッシュ ( /
gallery_bg.php) が表示されます。次のようにトリミングできます。
echo trim($_SERVER["REQUEST_URI"],"/");
またはURLを分割し/
て配列を作成し、配列から最後のアイテムを取得します
$array = explode("/",$url);
$last_item_index = count($url) - 1;
echo $array[$last_item_index];
また
echo basename($url);
$url = "http://domain/fotografo/admin/gallery_bg.php";
$keys = parse_url($url); // parse the url
$path = explode("/", $keys['path']); // splitting the path
$last = end($path); // get the value of the last element
これを試して:
Here you have 2 options.
1. Using explode function.
$filename = end(explode('/', 'http://domain/fotografo/admin/gallery_bg.php'));
2. Use basename function.
$filename = basename("http://domain/fotografo/admin/gallery_bg.php");
- ありがとう
$url = $_SERVER["PHP_SELF"];
$path = explode("/", $url);
$last = end($path);