PHP website ie pictures do not display pictures

王林
Release: 2023-05-28 21:16:06
Original
515 people have browsed it

Recently, when developing a website based on PHP, I encountered a very strange problem, that is, images cannot be displayed in the IE browser. This bothers me because the image displays fine in other browsers, only IE has problems.

After some investigation, I found that the root cause of the problem was that the image file name contained spaces or Chinese characters. Since IE's cache management mechanism is different from other browsers, when the image file name contains spaces or Chinese characters, IE will automatically encode it into Url encoding, but other browsers will not.

Specifically, when an image file name contains spaces or Chinese characters, IE will convert it into the following form:

http://example.com/images/Picture test .jpg

The picture is the Url encoding form of the Chinese character "picture", and is the Url encoding form of the space.

However, when referencing such an image in PHP, it needs to be decoded back to its original form, otherwise it cannot be displayed. Specifically, when using PHP's img tag to reference an image, the image path needs to be decoded through the urldecode() function, as shown below:

In this way, the image can be displayed normally in IE.

In addition, there are some other solutions, such as using the urlencode() function to encode the image path, or replacing spaces and Chinese characters in the image file name with other characters. However, these methods may cause other compatibility issues, so it is best to use the urldecode() function to decode to be compatible with all browsers.

In general, through this experience, I deeply realized the differences in encoding processing between different browsers, and I need to be extra careful during development.

The above is the detailed content of PHP website ie pictures do not display pictures. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!