如何替换 php 中已弃用的 set_magic_quotes_runtime?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2217955/
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
How can I replace the deprecated set_magic_quotes_runtime in php?
提问by Shawn
I'm getting this message when I try to run a php script I have to use but did not write.
当我尝试运行必须使用但未编写的 php 脚本时收到此消息。
Deprecated: Function set_magic_quotes_runtime() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/fpdf.php on line 1810
Here is line 1810:
这是第 1810 行:
set_magic_quotes_runtime(0);
If this is a deprecated function, what can I replace it with?
如果这是一个已弃用的功能,我可以用什么替换它?
Thank you very much!
非常感谢!
回答by philfreo
Check if it's on first. That should get rid of the warning and it'll ensure that if your code is run on older versions of PHP that magic quotes are indeed off.
首先检查它是否打开。这应该消除警告,它会确保如果您的代码在旧版本的 PHP 上运行,那么魔术引号确实关闭了。
Don't just remove that line of code as suggested by others unless you can be 100% sure that the code will never be run on anything before PHP 5.3.
不要只是按照其他人的建议删除那行代码,除非您可以 100% 确定该代码永远不会在 PHP 5.3 之前的任何东西上运行。
<?php
// Check if magic_quotes_runtime is active
if(get_magic_quotes_runtime())
{
// Deactivate
set_magic_quotes_runtime(false);
}
?>
get_magic_quotes_runtimeis NOT deprecated in PHP 5.3.
Source: http://us2.php.net/get_magic_quotes_runtime/
get_magic_quotes_runtime在 PHP 5.3 中未弃用。
来源:http: //us2.php.net/get_magic_quotes_runtime/
回答by testing
I used FPDF v. 1.53 and didn't want to upgrade because of possible side effects. I used the following code according to Yacoby:
我使用了 FPDF v. 1.53 并且由于可能的副作用而不想升级。我根据 Yacoby 使用了以下代码:
Line 1164:
第 1164 行:
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
$mqr=get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
}
Line 1203:
第 1203 行:
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($mqr);
}
回答by Doug T.
Since Magic Quotes is now off by default (and scheduled for removal), you can just remove that function call from your code.
由于 Magic Quotes 现在默认关闭(并计划删除),您可以从代码中删除该函数调用。
回答by RAMIL T.K
In PHP 7 we can use:
在 PHP 7 中,我们可以使用:
ini_set('magic_quotes_runtime', 0);
instead of set_magic_quotes_runtime(0);
代替 set_magic_quotes_runtime(0);
回答by Martin
Upgrade to version 1.6 of FPDF.
升级到 FPDF 1.6 版。
回答by Yacoby
You don't need to replace it with anything. The setting magic_quotes_runtimeis removed in PHP6so the function call is unneeded. If you want to maintain backwards compatibility it may be wise to wrap it in a if statement checking phpversionusing version_compare
你不需要用任何东西替换它。该设置magic_quotes_runtime是在PHP6去除,因此函数调用是不必要的。如果您想保持向后兼容性,最好将其包装在 if 语句中使用version_compare检查phpversion
回答by user187291
ini_set('magic_quotes_runtime', 0)
I guess.
我猜。
回答by Alaa Sadik
Gust add the prefix "@" before the function to be @set_magic_quotes_runtime(0); Not supported anymore in php 5.4, and don't remove or disable the function
在函数前加前缀“@”为@set_magic_quotes_runtime(0); php 5.4 不再支持,请勿移除或禁用该功能
回答by Somwang Souksavatd
add these code into the top of your script to solve problem
将这些代码添加到脚本的顶部以解决问题
@set_magic_quotes_runtime(false);
ini_set('magic_quotes_runtime', 0);
回答by Praveen Kumar
Update this function :
更新此功能:
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime(0);
}
else {
ini_set('magic_quotes_runtime', 0);
}
$magic_quotes = get_magic_quotes_runtime();
$file_buffer = fread($fd, filesize($path));
$file_buffer = $this->EncodeString($file_buffer, $encoding);
fclose($fd);
if ($magic_quotes) {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($magic_quotes);
}
else {
ini_set('magic_quotes_runtime', $magic_quotes);
}
}
return $file_buffer;

