zoukankan      html  css  js  c++  java
  • php操作url 函数等

    <?php
    
    // 获取文件名称
    echo basename("/data/www/test/filesystem.php"),"
    ";
    // 获取目录名称
    echo dirname("/data/www/test/filesystem.php"),"
    ";
    echo __DIR__,"
    ";
    
     
    
    // 操作一个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
      )
  • 相关阅读:
    com.android.ide.common.process.PrecessException:org.gradle.process....finished with non-zero exit value 1
    android 学习笔记(1)
    C#遍历指定文件夹中的所有文件(转)
    让TextView里面的文字逐个显示的动画效果实现(1)
    This Handler class should be static or leaks might occur(null) 解决办法 (转)
    Android开发 旋转屏幕导致Activity重建解决方法(转)
    SQLite 数据库
    【Android】error opening trace file: No such file or directory (2)
    WPF中的RichTextBox
    android中的 Toast 和 AlertDialog
  • 原文地址:https://www.cnblogs.com/firstForEver/p/4866358.html
Copyright © 2011-2022 走看看