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:
This file will lost the part 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
preguntado el 31 de julio de 12 a las 15:07
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');
Also, I never used it myself, but I would take a look at the php function códigourlen 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)
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
en lugar de
a href="../folder/blue sky.png"
With the correct syntax spaces in the address do not cause problems
You may use regex.
$file_name = "http://domain.com/folder/blue sky.png"; $file_name2 = preg_replace("/ /", "-", $file_name); echo $file_name2; //echos http://domain.com/folder/blue-sky.png
espero que esto ayude...