pathinfo()在php不同版本中对于对多字节字符处理的不同结果
phpinfo()函数在处理路径时,在php的低版本中无法处理多字节字符,这里测试的是php5.3和php5.6 的区别
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<?php// your code goes hereecho phpversion();print_r(pathinfo("/resources/img/stock/wxb001/美景.png")); 输出:5.6.4-2Array( [dirname] => /resources/img/stock/wxb001 [basename] => 美景.png [extension] => png [filename] => 美景)但是在php5.3.3版本中<?php// your code goes hereecho phpversion();print_r(pathinfo("/resources/img/stock/wxb001/美景.png")); 输出:5.3.3Array( [dirname] => /var/www/www.shima.jp.net/resources/img/stock/wxb001 [basename] => .png [extension] => png [filename] => )// 同时,在php5.3中basename()也会过滤掉多字节字符
echo basename('/resources/img/stock/wxb001/美景.png')
// 输出:.png
|
那么在低版本中可以使用下面方法来实现多字节字符的处理
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?php// your code goes here $file = '/resources/img/stock/wxb001/美景.png';
$file_dir = dirname($file );$file_basename = substr(strrchr($file, DIRECTORY_SEPARATOR), 1);$file_name = substr($file_basename, 0, strrpos($file_basename, "."));$file_extension = end(explode(".", $file_basename));echo $file_dir; // /resources/img/stock/wxb001echo $file_basename; // 美景.pngecho $file_name; // 美景echo $file_extension; // png |
A dwarf on a giant's shoulder sees the farther of the two.
站在巨人肩上的矮子看得比巨人远。
--A dwarf on a giant's shoulders

浙公网安备 33010602011771号