I get an array of image URL by php scanning image folders. Some of the image file names have white space. The part after white space got lost. for example: This file is fine:
http://domain.com/folder/blue-sky.png
This file will lost the part sky.png
http://domain.com/folder/blue sky.png
My code for scanning the folder has nothing to do with checking or manipulating file names. How can I get the full name of blue sky.png
without rename it to blue-sky.png
?
I encountered this problem but after experimenting with the answers above I realised that the real problem was that I had written my html link without the inverted commas - typically browsers are tolerant of this, but not if spaces are present.
i.e I had coded something like
a href=../folder/blue sky.png
instead of
a href="../folder/blue sky.png"
With the correct syntax spaces in the address do not cause problems
Space in url encoding are represented with the string "%20" so you may want to use str_replace to replace every instance of the " " character to the character "%20"
echo str_replace(' ', '%20', 'http://domain.com/folder/blue sky.png');
will output
http://domain.com/folder/blue%20sky.png
Complementary information
Also, I never used it myself, but I would take a look at the php function urlencode if I were you, it may contains useful information
Note : Url encode will transform every characters that is not standard of the string (so you may want to only use urlencode on the string that is your image name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With