php %22(双引号)突然添加到 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17187673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:27:17  来源:igfitidea点击:

%22 (double quotes) added to url out of nowhere

phpurltinymce

提问by Daanvn

I'm making a mail programm that wil be used to mail newsletters to customers, in the newsletters will be images and links. When I tested it on localhost everything worked fine and the links worked. However when I uploaded it to my website the links and image paths won't work anymore.

我正在制作一个邮件程序,用于向客户发送时事通讯,时事通讯中将包含图像和链接。当我在 localhost 上测试它时,一切正常,链接也有效。但是,当我将其上传到我的网站时,链接和图像路径将不再起作用。

For some reason it adds %22 (which I found out are double quotes ") to the links and paths so the link I mailed looks like this:

出于某种原因,它将 %22(我发现它是双引号“)添加到链接和路径中,因此我邮寄的链接如下所示:

/%22http//www.mywebsite.com/%22

/%22http//www.mywebsite.com/%22

And the image path looks like this:

图像路径如下所示:

%22http//www.mywebsite.com/content/someimage.jpg/%22

%22http//www.mywebsite.com/content/someimage.jpg/%22

I'm using TinyMCE to edit the newsletter and I've tried relative_urls : falseand convert_urls : falsebut that does nothing. I don't think this is a TinyMCE issue but I thought I'd mention it anyway.

我正在使用 TinyMCE 来编辑时事通讯,我已经尝试过relative_urls : falseconvert_urls : false但没有任何作用。我不认为这是 TinyMCE 的问题,但我想我还是会提到它。

I have no clue what is causing this so if anyone knows what it going on it would be great!

我不知道是什么导致了这种情况,所以如果有人知道发生了什么,那就太好了!

Update: I've checked my code and looked at the html of the text being send in the mail and there are no double quotes around the link at any time so my guess is that it is a server issue.

更新:我检查了我的代码并查看了邮件中发送的文本的 html,并且在任何时候链接周围都没有双引号,所以我猜测这是服务器问题。

回答by Kees Sonnema

This is a problem with magic_quotesCheck your phpinfo() to see if it is turned off. If you are able to turn it off You have to disable it in your php.ini.

这是magic_quotes检查您的 phpinfo() 以查看它是否已关闭的问题。如果您可以关闭它,您必须在 php.ini 中禁用它。

You can test if it's enabled or disabled with the following code:

您可以使用以下代码测试它是启用还是禁用:

<?php
echo "Magic quotes is ";
if (get_magic_quotes_gpc()) {
  echo "enabled.";
} else {
  echo "disabled";
}
?>

Another fix could be to use stripslashes()to remove the slashes. This most likely will solve the problem.

另一个修复方法是stripslashes()用来删除斜线。这很可能会解决问题。

Read the docs about stripslashes()HERE

阅读关于这里的文档stripslashes()

A quick example:

一个简单的例子:

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Edit: another thing you can try is to use html_entity_encode().

编辑:您可以尝试的另一件事是使用html_entity_encode().

An example:

一个例子:

<?php
$orig = "I'll \"walk\" the <b>dog</b> now";

$a = htmlentities($orig);

$b = html_entity_decode($a);

echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b; // I'll "walk" the <b>dog</b> now
?>

info HERE

信息在这里

Another SO answer. for html_entity_encode()in urls https://stackoverflow.com/a/10001006/1379394

另一个SO答案。对于html_entity_encode()网址 https://stackoverflow.com/a/10001006/1379394

回答by sz-xl

If you have no access to your php.ini file,the easiest way could be adding this to your .htaccess file:

如果您无权访问 php.ini 文件,最简单的方法是将其添加到您的 .htaccess 文件中:

php_flag magic_quotes_gpc Off

php_flag magic_quotes_gpc 关闭