您的位置:首页 > 其它

常用但又易遗忘的语句(不断更新)

2006-05-21 13:19 405 查看
dirname -- 返回路径中的目录部分
<?php
$path = "/etc/passwd";
$file = dirname ($path); // $file is set to "/etc"
?>
-----------------------------------------

basename -- 返回路径中的文件名部分
<?php
$path = "/home/httpd/html/index.php";
$file = basename ($path); // $file is set to "index.php"
$file = basename ($path,".php"); // $file is set to "index"
?>
------------------------------------------

pathinfo -- 返回文件路径的信息
<?php
$path_parts = pathinfo("/www/htdocs/index.html");
echo $path_parts["dirname"] . "/n";
echo $path_parts["basename"] . "/n";
echo $path_parts["extension"] . "/n";
?>
将输出:

/www/htdocs
index.html
html

--------------------------------------------------------

parse_url -- 解析 URL,返回其组成部分
array parse_url ( string url)
此函数返回一个关联数组,包含现有 URL 的各种组成部分。如果缺少了其中的某一个,则不会为这个组成部分创建数组项。组成部分为: scheme - 如 http

host

port

user

pass

path

query - 在问号 ? 之后

fragment - 在散列符号 # 之后

此函数并 意味着给定的 URL 是合法的,它只是将上方列表中的各部分分开。parse_url() 可接受不完整的 URL,并尽量将其解析正确。
注: 此函数对相对路径的 URL 不起作用。
---------------------------------------------------

realpath -- 返回规范化的绝对路径名

---------------------------------------------------

" ' " 跟 " /" " 包含字符串的区别

<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "/n";
?>
结果 This is a $string with my $name in it.
------------------

<?php
$string = 'cup';
$name = 'coffee';
$str = "This is a $string with my $name in it.";
echo $str. "/n";
?>
结果 This is a coffee with my cup in it.
---------------------------------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: