Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly url encode a string

I'm trying to parse a file name to a url string.

the file name is:

201-SALÃO DE JOGOS.jpg

I need the output be exactly this:

201-SAL%c3O%20DE%20JOGOS.jpg

I'm trying like this:

$var = 201-SALÃO DE JOGOS.jpg;
echo urlencode($var);

But instead it returns:

201-SAL%C3%83O+DE+JOGOS.jpg

This is not a valid url. I've already tried with htmlspecialchars() and htmlentities() but these do not work.

like image 993
Ivan Moreira Avatar asked Mar 13 '26 11:03

Ivan Moreira


1 Answers

You need rawurlencode

$filename = "201-SALÃO DE JOGOS.jpg";
print rawurlencode($filename);
like image 124
Bhavik Shah Avatar answered Mar 16 '26 01:03

Bhavik Shah