Two strange errors exist in PHP5.3! 1. test environment
CentOS 6 + PHP 5.3.3, updated to the latest status through yum on December 31, February 26, 2015.
2 Error Description 2.1 The basename () function returns the error result for the path of the UTF-8 encoding.
This is very easy to verify by creating a UTF-8 encoded php source file test. php with the following content:
'; $ Utf8Dir ='/var/www/html/A kitten B .txt '; echo basename ($ utf8Dir); echo'
'; $ Utf8Dir ='/var/www/html/AB .txt '; echo basename ($ utf8Dir); echo'
';
Access through a browser. the page is displayed as follows:
B .txt
A kitten B .txt
AB .txt
It can be seen that if the name does not start with an ASCII code, the Chinese characters in the name will be discarded until an ASCII character starts. In addition, this problem does not exist in dirname.
2.2 ZipArchive: extracloud () also has the same problem.
If the file in the. zip package is not a pure ASCII code, the Chinese characters in the file will be discarded. However, the file is still decompressed, but the name of the extracted file is incorrect. If the file name is a Chinese character, all files are discarded after decompression,
There is only one. and extension left in the result, thus forming a hidden file.
For example, after Microsoft txt is decompressed, it becomes. txt.
In my opinion, this method calls the problematic function basename (), which causes this problem.
2.3 strange
The above two problems do not exist when the php program is executed locally. That is to say, if you run PHP test. php on the host where the php engine is located, the above two problems no longer exist. Why? I personally guess the basename () internally depends on
Some environment variables, but these variables are not set correctly when accessed through web pages, resulting in problems. Please give answers to the experts for the reason... (I have been depressed for a day and hope someone can explain it)
3. how to deal with it
Because only the problem is found, but the real cause of the problem is not found, it cannot be solved directly. My countermeasure is to avoid using these two functions. if you need them, just write a similar function.