hai già provato questa?

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

es.

Codice PHP:
<?php $query_string 'foo=' urlencode($foo) . '&bar=' urlencode($bar); echo '<a href="mycgi?' htmlentities($query_string) . '">'?>