$ _SERVER []不会在localhost上的浏览器中返回当前url

$ _SERVER []不会在localhost上的浏览器中返回当前url

问题描述:

Following returns empty array, so on my localhost $_SERVER[] doesn't return anything. Why?

Url in browser looks like this: localhost/final/events/2012-10/

$current_url_all = parse_url($_SERVER['PATH_INFO']);
print_r($current_url_all);

What am I doing wrong? How else can I grab that last date piece from url?

以下返回空数组,因此我的localhost $ _SERVER []不会返回任何内容。 为什么? p>

浏览器中的Url如下所示:localhost / final / events / 2012-10 / p>

  $ current_url_all = parse_url($  _SERVER ['PATH_INFO']); 
print_r($ current_url_all); 
  code>  pre> 
 
 

我做错了什么? 我怎样才能从网址中获取最后一个日期文件? p> div>

Try to use $_SERVER["REQUEST_URI"] instad, $_SERVER['PATH_INFO'] seems to be just aviable if you invoke the script like a directory:

http://example.org/script.php/foo

You might want to use

$_SERVER['REQUEST_URI']

u can manipulate the string. use strpos to get the position of localhost/final/events/ then substring to get the rest.

also u can use $end = end((explode('/', $url)));

then get the last value from the array