urlencode() note

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@32141 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Rasmus Lerdorf 2000-09-06 16:58:53 +00:00
parent 561087fa75
commit ac45ab3255

View file

@ -221,12 +221,31 @@ while ($i < count ($a)) {
<example>
<title><function>Urlencode</function> example</title>
<programlisting role="php">
echo '&lt;A HREF="mycgi?foo=', urlencode ($userinput), '">';
echo '&lt;A HREF="mycgi?foo=', urlencode ($userinput), '"&gt;';
</programlisting>
</example>
</para>
<para>Note: Be careful about variables that may match HTML entities.
Things like &amp;amp, &amp;copy and &amp;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: <ulink url="&url.argsep;">&url.argsep;</ulink>
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;amp; instead of &amp; as the
separator. You don't need to change PHP's arg_separator for this. Leave
it as &amp;, but simply encode your URLs using:
<example>
<title><function>Urlencode/htmlentities</function> example</title>
<programlisting role="php">
echo '&lt;A HREF="mycgi?foo=', htmlentities (urlencode ($userinput) ), '"&gt;';
</programlisting>
</example>
<para>
See also <function>urldecode</function>,
<function>htmlentities</function>,
<function>rawurldecode</function>,
<function>rawurlencode</function>.
</para>