La funzione da usare era urlencode()

http://it.php.net/urlencode