2011-02-03 48 views
0

这里是我的代码用htmlspecialchars()或ヶ辆()不工作

$currentPage = SITE_URL.'/'.basename($_SERVER['PHP_SELF'])."?".substr($tail,1); 
//For example a URL 'http://php.net/docs.php 
' 
$currentPage = htmlspecialchars($currentPage); 
//$currentPage = htmlentities($currentPage); 

//I was hoping for a output like this 'http%3A%2F%2Fphp.net%2Fdocs.php ' 
echo $currentPage; //but I get http://php.net/docs.php again 

我得到完全相同的输出与输入

+0

使用$ _SERVER ['SCRIPT_NAME']而不是$ _SERVER ['PHP_SELF']。可以通过转到/index.php/someotherpage.php来欺骗$ _SERVER ['PHP_SELF']。除此之外,其他人说了些什么。 – igorw 2011-02-03 14:09:21

回答

0

我想你想要urlencode。它会将http://php.net/docs.php编码为http%3A%2F%2Fphp.net%2Fdocs.php,如你所愿。

0

根据手册:

此功能与 htmlspecialchars()在所有方面相同,除了 与htmlentities(),所有字符 其中有HTML字符实体 e这些实体被翻译成这些实体。

因此,如果没有看到原始输入,我只能假设原始输入不包含任何可以翻译的字符。

0

如果您获得相同的输出,则无法逃脱。

htmlentities()应该将<>&转换为实体等效项。它只剩下其他ASCII字符,如/:。因此,您的网址可能只包含这些内容,但不包含&