Two strange errors exist in PHP5.3!

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.