rawurlencode
(PHP 3, PHP 4 >= 4.0.0)rawurlencode -- URL-encode according to RFC1738
Descriptionstring rawurlencode (string str)
Returns a string in which all non-alphanumeric characters except -_.
 
have been replaced with a percent (%) sign followed by two hex digits. This is the encoding described in RFC1738 for protecting literal characters from being interpreted as special URL delimiters, and for protecting URL's from being mangled by transmission media with character conversions (like some email systems). For example, if you want to include a password in an FTP URL: Example 1. rawurlencode() example 1echo '<a href="ftp://user:', rawurlencode('foo @+%/'),
     '@ftp.my.com/x.txt">';
      
 
 
Or, if you pass information in a PATH_INFO component of the URL: Example 2. rawurlencode() example 2echo '<a href="http://x.com/department_list_script/',
    rawurlencode('sales and eting/Miami'), '">';
      
 
 
See also rawurldecode(), urldecode(), urlencode(). urlencode
(PHP 3, PHP 4 >= 4.0.0)urlencode -- URL-encodes string
Descriptionstring urlencode (string str)
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the RFC1738 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs. This function is convenient when encoding a string to be used in a query part of an URL, as a convenient way to pass variables to the next page: Example 1. urlencode() exampleecho '<a href="mycgi?foo=', urlencode($userinput), '">';
      
 
 
Note: Be careful about variables that may match HTML entities. Things like &amp, &copy and &pound are parsed by the browser and the actual entity is used instead of the desired variable name. This is an obvious hassle that the W3C has been telling people about for years. The reference is here: http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2 PHP supports changing the argument separator to the W3C-suggested semi-colon through the arg_separator .ini directive. Unfortunately most user agents do not send form data in this semi-colon separated format. A more portable way around this is to use &amp; instead of & as the separator. You don't need to change PHP's arg_separator for this. Leave it as &, but simply encode your URLs using htmlentities()(urlencode($data)). Example 2. urlencode/htmlentities() exampleecho '<a href="mycgi?foo=', htmlentities(urlencode($userinput)), '">';
      
 
 
See also urldecode(), htmlentities(), rawurldecode(), rawurlencode().