PHP 的 urlencode() 是針對參數值
vs
htmlspecialchars() or htmlentities() 是針對整個 ? 後的查詢字串
(前提最好每個參數值都已 urlencode 過)
urlencode()
http://www.php.net/manual/en/function.urlencode.php
直接看底下 PHP 官方提供的範例,來理解用法最快…
Example #1 urlencode() example
程式碼:
<?php echo '<a href="mycgi?foo=', urlencode($userinput), '">'; ?> |
Example #2 urlencode() and htmlentities() example
程式碼:
<?php $query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar); echo '<a href="mycgi?' . htmlentities($query_string) . '">'; ?> |
相關文章 Related posts:


