PHP获取uri并进行解析

//获得url
echo $_SERVER["REQUEST_URI"];
//对url进行解析   解析成固定键值的数组
$url = parse_url("http://abc..xyz/YG/employee/index.php/Home/Index/main.html");
var_dump($url);

结果:

    array (size=3)

      'scheme' => string 'http' (length=4)

      'host' => string 'abc.xyz' (length=14)

      'path' => string '/YG/employee/index.php/Home/Index/main.html' (length=43)

    /dong/07.php

 

$url = 'http://username:password@hostname:9090/path?arg=value#anchor';

var_dump(parse_url($url));
var_dump(parse_url($url, PHP_URL_SCHEME));
var_dump(parse_url($url, PHP_URL_USER));
var_dump(parse_url($url, PHP_URL_PASS));
var_dump(parse_url($url, PHP_URL_HOST));
var_dump(parse_url($url, PHP_URL_PORT));
var_dump(parse_url($url, PHP_URL_PATH));
var_dump(parse_url($url, PHP_URL_QUERY));
var_dump(parse_url($url, PHP_URL_FRAGMENT));
array(8) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(8) "hostname"
  ["port"]=>
  int(9090)
  ["user"]=>
  string(8) "username"
  ["pass"]=>
  string(8) "password"
  ["path"]=>
  string(5) "/path"
  ["query"]=>
  string(9) "arg=value"
  ["fragment"]=>
  string(6) "anchor"
}
string(4) "http"
string(8) "username"
string(8) "password"
string(8) "hostname"
int(9090)
string(5) "/path"
string(9) "arg=value"
string(6) "anchor"

分享一篇文章:http://blog.sina.com.cn/s/blog_686999de0100jgda.html

你可能感兴趣的:(php)