PHP pathinfo() 函数

PHP 教程 · 2019-01-25 13:27:16

定义和用法

pathinfo() 函数以数组的形式返回关于文件路径的信息。

返回的数组元素如下:

  • [dirname]: 目录路径
  • [basename]: 文件名
  • [extension]: 文件后缀名
  • [filename]: 不包含后缀的文件名

语法


pathinfo(path,options)


参数 描述
path 必需。规定要检查的路径。
options 可选。规定要返回的数组元素。默认是 all。

可能的值:

  • PATHINFO_DIRNAME - 只返回 dirname
  • PATHINFO_BASENAME - 只返回 basename
  • PATHINFO_EXTENSION - 只返回 extension
  • PATHINFO_FILENAME - 只返回 filename

提示和注释

注释:如果不是请求所有的元素,则 pathinfo() 函数返回字符串。

实例

实例 1

<?php print_r(pathinfo("/testweb/test.txt")); ?>

上面的代码将输出:

Array
(
    [dirname] => /testweb
    [basename] => test.txt
    [extension] => txt
    [filename] => test
)

实例 2

<?php print_r(pathinfo("/testweb/test.txt",PATHINFO_BASENAME)); ?>

上面的代码将输出:

test.txt

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Ethnography and Virtual Worlds

Ethnography and Virtual Worlds

Tom Boellstorff、Bonnie Nardi、Celia Pearce、T. L. Taylor / Princeton University Press / 2012-9-16 / GBP 21.00

"Ethnography and Virtual Worlds" is the only book of its kind - a concise, comprehensive, and practical guide for students, teachers, designers, and scholars interested in using ethnographic methods t......一起来看看 《Ethnography and Virtual Worlds》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具