note 50527 deleted from function.urlencode by nlopess
| From: | nlopess@php.net | Date: | Thu, 14 Apr 2005 16:05:29 +0000 |
| Subject: | note 50527 deleted from function.urlencode by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-88021@lists.php.net to get a copy of this message | ||
Note Submitter: botsmith at hotmail dot com
----
I don't see why Example 2 recommends htmlentities(urlencode($data)). Since urlencode() already
converts the non-alphanumeric characters to hexadecimal, htmlentities() would have nothing left to
convert. On the other hand, I can understand using something like this:
<?php
$url = 'mycgi?foo1=' . urlencode($userinput1) . '&foo2=' .
urlencode($userinput2);
echo '<a href="' . htmlentities($url) . '">';
?>
I.e. urlencode() the individual pieces of data, then run the whole url thru htmlentities() to
convert the & that separates the form variables into &.
A great see-also is http_build_query() (which is available in the PEAR package PHP_Compat for those
of us who haven't gone to PHP5 yet). It does the urlencode for you, but you would still want to
do the htmlentities on the url after it is built.