zoukankan      html  css  js  c++  java
  • php常用的路径有关的函数

    简单整理一下工作中经常用到的php路径函数

    1、basename($path, $suff):返回基本的文件名,如果是以$suff 结束的就去掉

    $path = 'E:centosindex.php';
    echo basename($path, '.php');  // index
    echo basename($path);  // index.php

    2、dirname($path)返回路径中的目录部分

    $url = 'http://www.baidu.com/abc/index.php?id=1';
    echo dirname($url); // http://www.baidu.com/abc

    3、realpath($path)返回规范化的绝对路径名

    $path = '../phpinfo.php';
    echo realpath($path);    // E:wampApache2.2htdocsphpinfo.php

    4、pathinfo($path, [int $options])返回文件路径的信息,option 可以指定返回那些单元

    $url = 'http://www.baidu.com/abc/index.php?id=1';
    $res = pathinfo($url);
    echo $res['dirname'];    // http://www.baidu.com/abc
    echo $res['basename']; // index.php?id=1
    echo $res['extension']; // php?id=1
    echo $res['filename']; //  index

    5、parse_url($url)解析 URL,返回其组成部分

    $url = 'http://www.baidu.com/abc/index.php?id=1#test';
    $res = parse_url($url);
    echo $res['scheme'];    // http
    echo $res['host'];    // www.baidu.com
    echo $res['path'];    // /abc/index.php
    echo $res['query'];    // 在问号之后的:id=1
    echo $res['fragment'];    // 在#之后:test
  • 相关阅读:
    [转载]解析用户生命周期价值:LTV
    [整理]VS2013常用插件
    Extjs4 tabpanel 中表单定宽居中
    idea创建ssm项目
    shiro框架的学习
    mysql
    springboot
    idea配置
    Spring MVC
    关于web乱码问题
  • 原文地址:https://www.cnblogs.com/hanpengyu/p/4265627.html
Copyright © 2011-2022 走看看