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 here echo phpversion(); print_r( pathinfo ( "/resources/img/stock/wxb001/美景.png" )); 输出: 5.6.4-2 Array ( [dirname] => /resources/img/stock/wxb001 [ basename ] => 美景.png [extension] => png [filename] => 美景 ) 但是在php5.3.3版本中 <?php // your code goes here echo phpversion(); print_r( pathinfo ( "/resources/img/stock/wxb001/美景.png" )); 输出: 5.3.3 Array ( [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/wxb001 echo $file_basename ; // 美景.png echo $file_name ; // 美景 echo $file_extension ; // png |