I use getimagesize
to judge an image height and size.
Wh开发者_高级运维en a url has space, the getimagesize
echo's an error. I've tried using urlencode()
to transfer all the url address, it still returns an error. I noticed that if I just change the space into %20
, getimagesize
runs ok.
I have no idea why?
I also tired to use $newurl = preg_replace(' ', '%20', $url);
It echo'ed :
Warning: preg_replace() [function.preg-replace]: Empty regular expression
So how to preg_replace
correctly. And is there a way to transfer the url correctly with getimagesize
so that it passes all possible test cases.
Thanks
you should use str_replace(' ', "%20", $url)
instead of preg_replace(' ', '%20', $url);
urldecode()
is the function you want to use to decode all those characters back after you've converted them before processing the image. Run the string containing the URL through that.
If only the file name contains spaces you can use rawurlencode().
$url = dirname($url) . '/'. rawurlencode(basename($url));
Can you post some example code from when you tried to use urlencode? Also, you don't need to use preg_replace for the last bit, you can simply use str_replace.
精彩评论