Home > Backend Development > PHP Tutorial > PHP的函数没法获得中文路径中的目录部分及文件名部分

PHP的函数没法获得中文路径中的目录部分及文件名部分

WBOY
Release: 2016-06-13 10:59:40
Original
1192 people have browsed it

PHP的函数无法获得中文路径中的目录部分及文件名部分

问题:PHP中获得路径中目录部分的函数有以下两个

dirname — 返回路径中的目录部分

pathinfo — 返回文件路径的信息。

如:

$path_parts = pathinfo("/www/htdocs/index.html");
echo $path_parts["dirname"] . "\n";
echo $path_parts["basename"] . "\n";
echo $path_parts["extension"] . "\n";
?>
但是当路径中带有中文时,就无法正常获得,只会返回字符‘.’,

解决:

自己写一个函数获得,

function getDir($path)

{

 return(substr($path,0,strrpos($path,"\\")));

}

其实就是简单的字符串处理。


来自东子的博客

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template