• 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
      )
  • 相关阅读:
    2.4 使用vue-cli创建项目/项目打包/发布
    2.3 vue-cli脚手架工具/nodejs
    2.2 vue的devtools、eslint检测问题
    2. es6扩展运算符
    文件json
    函数
    函数不固定参数
    监控日志,加入黑名单
    非空即真
    随机生成手机号,存入文件
  • 原文地址:https://www.cnblogs.com/firstForEver/p/4866358.html
Copyright © 2020-2023  润新知