Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urlencode except /

Tags:

php

urlencode

Is there a way to urlencode except directory seperators / in the path ?

like

urlencode('/this/is/my/file right here.jpg');
like image 698
Chris Avatar asked May 14 '10 13:05

Chris


2 Answers

Replace them again:

str_replace('%2F', '/', urlencode('/this/is/my/file right here.jpg'));

Note that if you are going to pass the result in a query string, you should not do the replacement above -- use only urlencode. If you are using it in the path portion, you ought to use rawurlencode instead.

like image 157
Artefacto Avatar answered Sep 25 '22 23:09

Artefacto


This should solve your problem.

str_replace("%2F","/",urlencode('/this/is/my/file right here.jpg'));
like image 32
Sam152 Avatar answered Sep 25 '22 23:09

Sam152