PHP 转义查询字符串变量
我在 Web 应用程序中创建了一个表单,该表单只有一个文本字段,并且该字段使用 GET 发布到 PHP 页面,但我观察到奇怪的行为。即,当我在本地服务器上测试它时,接收到的文本与文本字段中写入的一样,但是当我将其上传到在线服务器时,接收到的字符串会自动转义,这意味着所有单引号和双引号都会被转义。例如,如果我写 It's not true...
那么在 php 方面我会得到
$comment = $_REQUEST["comm"];
print $comment;
//will print It\'s not true... on my online server
//will print It's not true... on my local server
我还无法理解为什么会这样?是否有任何 PHP 设置可以自动转义查询字符串变量?
I have created a form in my web application which has only a single text field and that field is posted to a PHP page using GET, but I am observing strange behavior. i.e. when I test it on my local server, the text is received as it was written in the text field, but when I upload it to my online server, the received string is escaped automatically means, all single quotes and double quotes are escaped. e.g. If I write It's not true...
then on php side I will get
$comment = $_REQUEST["comm"];
print $comment;
//will print It\'s not true... on my online server
//will print It's not true... on my local server
I am yet unable to under stand why is it so? Is there any PHP setting for escaping Query Strings variables automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已启用“魔术引号”。它们是一个可怕的错误功能,幸运的是在下一版本的 PHP 中被删除。 PHP 手册有一个指南来禁用它们。
简而言之,您需要在
php.ini
文件中将以下配置项设置为Off
:具体来说,您的问题似乎与
magic_quotes_gpc< /code> - “gpc”部分是“GET、POST 和 COOKIE”的缩写 - 但最好将它们全部禁用。
You have "magic quotes" enabled. They're a terrible misfeature which are luckily being removed in the next version of PHP. The PHP manual has a guide to disabling them.
In short, you need to set the following configuration items to
Off
in yourphp.ini
file:Specifically, your problem appears to be with
magic_quotes_gpc
- the "gpc" portion being short for "GET, POST, and COOKIE" - but it's good practice to keep all of them disabled.代码会告诉你你需要的一切......
创建上面的函数并将值传递给这个函数
,然后调用这些值,就像
我希望你可以通过注释得到所有解释......
Code will tell you every thing what you need..
create above function and pass-on values to this function
and then call the values like
I hope you may get every thing explained via comments...
我认为它是 php.ini 文件中的设置。您可以调用 PHP 函数来禁用它,但那时为时已晚。
I think its a setting within the php.ini file. You can call a PHP function to disable it, but by then it's too late.