PHP常用命令
pathinfo (path,options)
pathinfo() 函数以数组的形式返回关于文件路径的信息。
print_r(pathinfo("/testweb/test.txt"));
// return
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
[filename] => test
)
// 可选参数 PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION, PATHINFO_FILENAME
print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME));
// return
test.txt
parse_url()
$test = parse_url("http://localhost/index.php?name=tank&sex=1#top");
print_r($test);
// return
Array
(
[scheme] => http //使用什么协议
[host] => localhost //主机名
[path] => /index.php //路径
[query] => name=tank&sex=1 // 所传的参数
[fragment] => top //后面根的锚点
)
basename (path,suffix)
basename() 函数返回路径中的文件名部分。
suffix: 可选。规定文件扩展名。如果文件有名有文件扩展名,将不会显示这个扩展名。
<?php
$path = "/testweb/home.php";
//Show filename with file extension
echo basename($path) ."<br/>";
//return
home.php
//Show filename without file extension
echo basename($path,".php");
//return
home
$test = basename("http://localhost/index.php?name=tank&sex=1#top");
echo $test;
//return
index.php?name=tank&sex=1#top