php - How to convert this url to %20? -
There is a very simple problem that can be solved for a long time, but I am not getting what I need. / P>
I have an image URL like this:
$ image = 'http://perfumepalace.arctechsolution.com/image/cache/data/another/ For him / Believe 100 ml EDP-150x150.jpg ';
and want output as
http://perfumepalace.arctechsolution.com/image/cache/data/another/For%20Her/ Believe% 20100ml% 20EDP-150x150.jpg
Yes, you will tell me that I can use urlencode or rawurlencode. I believe I have tried and still there is no luck.
I like this with urlencode
http% 3A% 2F% 2Fperfumepalace.arctechsolution.com% 2Fimage% 2Fcache% 2Fdata% 2Fanother% 2FFor +% 2FBelieve + 100ml + EDP-150x150.jpg
And with rawurlencode I have received the output like this:
http% 3A% 2F% 2Fperfumepalace.arctechsolution .com% 2Fimage% 2Fcache% 2Fdata% 2Fanother% 2FFor% 20Her% 2FBelieve% 20100ml% 20EDP- 150x150.jpg
Straw_Replay
I can get the same Is what I want to do:
str_replace ('+', '% 20', $ image);
The result will be: http://perfumepalace.arctechsolution.com/image/cache/data/another/For%20Her/Believe%20100ml%20EDP-150x150.jpg
But I want to use them urlencode or rawurlencode. But these functions also convert signals into slash / part
Is there a way to encode URLs only in the URL?
EDIT: Yes, I can write only one part of the ULL in BESNAME () but there can also be space characters in the directory name, so the possibility of changing the file name is not here .
And in fact i want to know that i can use rawurlencode in urlencode, or full url without affecting '/' i suggest that regex eigher did not want to.
Note: The complexity is that the url path is not fixed for 'its' directory section, and the directory level is also fixed.
what do you want , but only the required part of your url is encoded Change
Example:
$ image = sprintf ('http://perfumepalace.arctechsolution.com/image/cache/data/another/%s/%s', Rawurlencode ('for her'), crude lincoln ('Believe 100ml EDP-150x150.jpg'));
But if you still want to apply to the whole URL string, you can do the following:
function my_url_encode ($ url) {$ Info = parse_url ($ url); Return (sprintf '(% / s, $ information [' path '])))); }
Comments
Post a Comment