function encode_3986($string) { $string = rawurlencode($string); return str_replace('%7E', '~', $string); // prior to PHP 5.3, rawurlencode was RFC 1738 }