PHP 不断转义我的表单输入(在我的 ' 后面添加 \)
因此,基本上,当我输入带有撇号的内容(例如约翰的自行车)时,它会与约翰的自行车相呼应。代码如下:
<?php
$searchname = $_POST["name"] ;
echo "$searchname";
我的表单使用 POST 方法。有什么办法可以阻止这种情况吗?
另外,为了使输入不区分大小写,我将如何在这一部分中进行操作?
$searchsport = $_POST['sport'];
$sportarray = array(
"Football" => "Fb01",
"Cricket" => "ck32",
"Tennis" => "Tn43",
);
if(isset($sportarray[$searchsport])){
header("Location: ".$sportarray[$searchsport].".html");
die;
}
//what code is needed to make the if statement work? I've looked up some weird ways such as using array_change_key_case (which I clearly don't understand).
So basically when I type something with an apostrophe, such as John's bike it will echo John\'s bike. The code below:
<?php
$searchname = $_POST["name"] ;
echo "$searchname";
My form uses the POST method. Is there any way to stop this?
Also to make input case insensitive how would I go about in this segment?
$searchsport = $_POST['sport'];
$sportarray = array(
"Football" => "Fb01",
"Cricket" => "ck32",
"Tennis" => "Tn43",
);
if(isset($sportarray[$searchsport])){
header("Location: ".$sportarray[$searchsport].".html");
die;
}
//what code is needed to make the if statement work? I've looked up some weird ways such as using array_change_key_case (which I clearly don't understand).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这很可能是因为您有魔术引号打开,试试这个:
事实上,您可以创建一个函数来自动为您执行此操作:
然后您可以简单地执行以下操作:
注意: 您还可以禁用 php.ini 中丑陋的魔术引号因为它们是有问题的并且正确地被弃用并且不再是 PHP 的未来版本。
This is most likely because you have magic quotes turned on, try this:
In fact, you could create a function instead to do it automatically for you:
And then you can simply do:
Note: You can also disable the ugly magic quotes from php.ini as they are problematic and rightly deprecated and out of the future versions of PHP.
有几种方法。
关闭magic_quotes_gpc在 php.ini 中
<前><代码>magic_quotes_gpc = 0
在请求的开头,运行 stripslashes
编辑:添加 !function_exists 部分。这样,您不必担心之前是否运行过它,如果它已经运行过(通过另一个文件等),它就会跳过它
There are a few ways.
Turn off magic_quotes_gpc in php.ini
In the beginning of the request, run stripslashes
EDIT: Added the !function_exists part. This way, you don't need to worry if you ran it before, it'll just skip it if it's already been run (by another file, etc)
这是由
magic_quotes_gpc< 控制的/code>
配置变量。这确实很烦人(并且已弃用!)。
您应该在 php.ini 中将其关闭,或者询问您的网络托管服务商是否可以对此采取措施。
如果不能,您可以使用
addslashes
和stripslashes
手动转义/取消转义。但请注意 - 您应该使用比addslashes
更安全的东西来提交到数据库。mysql_real_escape_string
是更好的选择,或者特定于您的数据库的函数:mysqli_escape_string
sqlite_escape_string
This is controlled by the
magic_quotes_gpc
configuration variable. It really is annoying (and deprecated!).You should turn it off in
php.ini
, or ask your web host if they can do something about it.If they can't, you can use
addslashes
andstripslashes
to manually escape/un-escape. Beware, though - you should use something more secure thanaddslashes
for submitting to a database.mysql_real_escape_string
is a better option, or the function specific to your database:mysqli_escape_string
sqlite_escape_string
我在配置文件中包含以下脚本,以在必要时修复魔术引号。这样我就不必担心主机的魔术引号设置。
I include the following script within my config file to fix magic quotes if necessary. That way I don't have to worry about the magic quotes settings of the host.
Magic Quotes...当 PHP 6 最终到来并消除这个不兼容的怪物时,我会非常高兴。
最好的解决方案是通过设置在 php.ini 中关闭它
如果您无权访问 php.ini 但正在使用 Apache,您还可以在
.htaccess
文件中禁用它:沟渠方案是在您的应用程序中禁用它。 PHP 手册的 禁用 Magic Quotes 页面建议使用此方法:
Magic Quotes... I'll be so happy when PHP 6 finally arrives and removes this monster of incompatibility.
The best solution is to turn it off in php.ini by setting
If you don't have access to php.ini but are using Apache, you can also disable it in an
.htaccess
file:The last ditch scenario is to disable it in your application. the PHP Manual's Disabling Magic Quotes page suggests using this: