このようなURLのページを実行していますhttp://www.domain.com/test/reports/index.php
index.php を使用せずに php を使用して URL を取得する必要があります
http://www.domain.com/test/reports/
このようなURLのページを実行していますhttp://www.domain.com/test/reports/index.php
index.php を使用せずに php を使用して URL を取得する必要があります
http://www.domain.com/test/reports/
parse_urlを使用します。
$url = (($_SERVER['HTTPS']=="on")?"https://":"http://").$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URL'];
$parts = parse_url($url);
$urlpath = $parts['scheme']."://".$parts['host'].$parts['path'];
<?php
$url = 'http://www.domain.com/test/reports/index.php';
$file_name = basename($url);
echo str_replace($file_name, '', $url);
?>
爆発内破でこれを行うための初心者の方法
<?php
$url = "http://www.domain.com/test/reports/index.php";
$newurl = explode("/", $url);
array_pop($newurl);
implode("/",$newurl);
?>
徹底するには、 parse_url()から始めたいと思うでしょう。
$parts=parse_url("http://domain.com/user/100");
これにより、少数のキーを持つ配列が得られます。あなたが探しているのは ですpath
。
パスを分割し/
、最後のパスを取ります。
$path_parts=explode('/', $parts['path']);
あなたの ID は にあり$path_parts[count($path_parts)-1]
ます。