php操作url 函数等

 

<?php

// 获取文件名称
echo basename("/data/www/test/filesystem.php"),"\n";
// 获取目录名称
echo dirname("/data/www/test/filesystem.php"),"\n";
echo __DIR__,"\n";

 

// 操作一个url,获取相关信息(注意php函数的使用

// parse_url处理url足够了。。第二个可选参数是php常量,直接获取数组中的某个value
$url_info = parse_url('http://www.google.com/abc/xyz/fck.php?id=1#sharp');
var_dump($url_info);
$result = pathinfo($url_info['path']);// pathinfo()可以info出一些文件名、目录名、后缀名等信息
var_dump($result);


/**
array(5) {
["scheme"]=>
string(4) "http"
["host"]=>
string(14) "www.google.com"
["path"]=>
string(16) "/abc/xyz/fck.php"
["query"]=>
string(4) "id=1"
["fragment"]=>
string(5) "sharp"
}

array(4) {
["dirname"]=>
string(8) "/abc/xyz"
["basename"]=>
string(7) "fck.php"
["extension"]=>
string(3) "php"
["filename"]=>
string(3) "fck"
}


**/

 

php中全局变量$_SERVER的一个例子:http://www.test.com/a/b/one.php?a=12#shart

Array
  (
  [USER] => nginx
  [HOME] => /var/cache/nginx
  [FCGI_ROLE] => RESPONDER
  [QUERY_STRING] => a=12
  [REQUEST_METHOD] => GET
  [CONTENT_TYPE] =>
  [CONTENT_LENGTH] =>
  [SCRIPT_NAME] => /a/b/one.php
  [REQUEST_URI] => /a/b/one.php?a=12
  [DOCUMENT_URI] => /a/b/one.php
  [DOCUMENT_ROOT] => /data/www/test
  [SERVER_PROTOCOL] => HTTP/1.1
  [GATEWAY_INTERFACE] => CGI/1.1
  [SERVER_SOFTWARE] => nginx/1.6.2
  [REMOTE_ADDR] => 192.168.80.190
  [REMOTE_PORT] => 54281
  [SERVER_ADDR] => 192.168.0.99
  [SERVER_PORT] => 80
  [SERVER_NAME] => www.test.com
  [REDIRECT_STATUS] => 200
  [SCRIPT_FILENAME] => /data/www/test/a/b/one.php
  [HTTP_HOST] => www.test.com
  [HTTP_CONNECTION] => keep-alive
  [HTTP_CACHE_CONTROL] => max-age=0
  [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
  [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
  [HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
  [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8
  [PHP_SELF] => /a/b/one.php
  [REQUEST_TIME] => 1456887300
  )
posted @ 2015-10-10 11:38  根号五  阅读(362)  评论(0编辑  收藏  举报