Close

Not a member yet? Register now and get started.

lock and key

Sign in to your account.

Account Login

Forgot your password?

PHP urlencode() 使用注意事項

 

的 urlencode() 是針對參數值
vs
htmlspecialchars() or htmlentities() 是針對整個 ? 後的查詢字串
(前提最好每個參數值都已 urlencode 過)

urlencode()
http://www.php.net/manual/en/function.urlencode.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) . '">';
?>

Leave a Reply

*