Can I include % in the image file name which is used in a web page?

Viewed 142

I name an image file 100%-satisfaction-guarantee-icon.png and then put it in my webpage, as below:

<img src="<?php bloginfo('template_directory'); ?>/images/100%-satisfaction-guarantee-icon.png" alt="100% Satisfaction Guarantee" width="124" height="126" />

But the image will not show. Can '%' be used in an image file name? And which rules are applied to file names for web pages?

I have also tried to use %25 for the % sign, but it seems not be working.

https://www.datanumen.com/wp-content/themes/datanumen/images/100%25-satisfaction-guarantee-icon.png still returns the 404 error.

3 Answers

Yes, you can simply percent-encode the % symbol. You can put %25 instead of %

So instead of

100%-satisfaction-guarantee-icon.png

you could refer to it as

100%25-satisfaction-guarantee-icon.png

A % in a path signifies encoding the URL for the purpose of using special characters (replaces unsafe ASCII characters). I believe this also applies to img tags in HTML.

Check out this wiki link Percent-encoding or this W3 resource HTML Encoding for more information.

You must know that in the Google Chrome URL bar, if you use space, then it is represented as %20. So regret using % in your file names while it is a bad practice.

Suggested file name: 100_percentage_satisfaction_guarantee_icon.png

Related