To do this, you need some function to change characters like the ampersand (&) into their hex equivalents for the query string.
Something like this:
function intoHex($char) {
return '%'.bin2hex($char);
}
$myString = 'a & b';
print preg_replace("/([^\w\d])/e","intoHex('"."\\1"."')",$myString);
Note that that last preg was formatted for a pre 4.04 version of PHP...Newer versions may require a slight change.
hope this helps,
brendanc@icehouse.net