Luciano Nascimento
Luciano Nascimento

Reputation: 2600

Best way to handle w/ Accents and Spaces in the URL ($_GET)

I need to handle with accents and spaces in $_GET['city'] parameter.

Whats the best way to post and receive it?

http://www.teste.com/?city=São Paulo

Thanks Luciano

Upvotes: 1

Views: 1139

Answers (2)

vinu
vinu

Reputation: 658

How about str_replace()?

Send city with

$cityurl = str_replace(' ', '_',$cityurl);//replace spaces with "_"

And the link is

http://www.teste.com/?city=$cityurl //url is like http://www.teste.com/?city=São_Paulo

Receive city with

$city = str_replace('_', ' ',$_GET['city']);//replace "_" with spaces

Upvotes: 0

Wes Cossick
Wes Cossick

Reputation: 2933

Probably best to use the urlencode() function in PHP before you pass the data over $_GET. Then on the receiving end, use urldecode().

http://php.net/manual/en/function.urlencode.php

Upvotes: 2

Related Questions