[英]There appears amp; in the url. How can I remove that?
http://localhost/rootfolder/contact.php?msg=empty&success=empty http://localhost/rootfolder/contact.php?msg = empty& success = empty
What is that amp;? 那是什么放大器? When I click two times on the button, that occurs. 当我在按钮上单击两次时,发生这种情况。 What do I have to do different? 我必须做些什么?
Currently, I am creating a website where you can subscribe to a newsletter and you can send a message directly on the website. 目前,我正在创建一个网站,您可以在其中订阅新闻通讯,也可以在该网站上直接发送消息。 To return to the previous page, I use a session and also the $_SERVER superglobal. 要返回上一页,我使用一个会话以及$ _SERVER超全局变量。 To keep the parameters in the url and also to change them, I wrote a function: 为了将参数保留在URL中并进行更改,我编写了一个函数:
function changeurl($page, $searched, $replacement) {
$strfinalone = "";
$strfinaltwo = "";
if(!(count(explode("?", $page))<= 1)) {
$a = explode("?", $page);
if(strlen($a[1]) == 0) {
$strfinaltwo = $a[0]."?".$searched."=".$replacement;
return $strfinaltwo;
}
if(!(count(explode("&", $a[1])) <= 1)) {
$b = explode("&", $a[1]);
for ($i=0; $i < count($b) ; $i++) {
$e = explode("=", $b[$i]);
if(strstr($e[0], $searched) !== false) {
if($e[1] == $replacement) {
return $a[0]."?".$a[1];
}
$str = $e[0];
$e[1] = $replacement;
$strfinalone = join("=", $e);
$b[$i] = $strfinalone;
$a[1] = join("&", $b);
$strfinaltwo = join("?", $a);
return $strfinaltwo;
}
}
$strfinaltwo = $page."&".$searched."=".$replacement;
return $strfinaltwo;
} else {
$d = explode("=", $a[1]);
if($d[0] == $searched) {
if($d[1] == $replacement) {
return $a[0]."?".$a[1];
}
$strfinaltwo = $a[0]."?".$searched."=".$replacement;
return $strfinaltwo;
} else {
$strfinaltwo = $a[0]."?".$a[1]."&".$searched."=".$replacement;
return $strfinaltwo;
}
}
} else {
$strfinaltwo = $page."?".$searched."=".$replacement;
return $strfinaltwo;
}
}
// TO GET THE URL:
$link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http").":"."//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$escaped_url = htmlspecialchars($link, ENT_QUOTES, 'UTF-8');
I just want to remove this amp; 我只想删除这个放大器; of the url when I click for example two times the subscribe button and there was nothing filled in. 例如,当我单击两次订阅按钮时,URL的内容并没有填写。
This is because of htmlspecialchars() which is used to some html characters. 这是因为htmlspecialchars()用于某些html字符。
And to encode url you can use urlencode() function. 要对网址进行编码,您可以使用urlencode()函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.