How to give encodeURIComponent for a link [closed]

自作多情 提交于 2020-01-14 06:04:29

问题


I need to give encodeURIComponent for a link. This question is related to the answer of PHP variable error in unicode. please help me.

<?php
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
$NewValue="";
if(!empty($_GET['NewValue'])){
    echo $NewValue=$_GET['NewValue'];//this variable is the problem;
    }
$Value="நன்றி";
?>
<a href="test1.php?NewValue=<?php echo $Value;?>">Click here</a>                
</body>
</html>

回答1:


In the other question before you were using JavaScript to append the value to the URL, therefor encodeURIComponent was the right choice.

The problem now is basically the same – here

<a href="test1.php?NewValue=<?php echo $Value;?>">Click here</a>

you are also putting a variable into a URL context (only this time using PHP), and so it should be properly encoded as well.

urlencode is kinda like PHP’s “version” of encodeURIComponent – so:

<a href="test1.php?NewValue=<?php echo urlencode($Value);?>">Click here</a>


来源:https://stackoverflow.com/questions/36534847/how-to-give-encodeuricomponent-for-a-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!