我怎样才能取代在PHP中不推荐使用的set_magic_quotes_runtime?

当我尝试运行我必须使用但未写入的PHP脚本时,收到此消息。

Deprecated: Function set_magic_quotes_runtime() is deprecated in /opt/lampp/htdocs/webEchange/SiteWeb_V5/inc/fpdf.php on line 1810 

这里是1810行:

 set_magic_quotes_runtime(0); 

如果这是一个弃用的function,我可以用什么来replace它?

非常感谢你!

检查一下是否打开。 这应该摆脱警告,它会确保如果您的代码运行在旧版本的PHP,魔术报价确实closures。

不要只是像其他人所build议的那样删除那行代码,除非你能够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_runtime在PHP 5.3中不被弃用。
来源: http : //us2.php.net/get_magic_quotes_runtime/

我使用了FPDF 1.53版本,并且不想升级,因为可能有副作用。 根据Yacoby,我使用了下面的代码:

1164行:

 if (version_compare(PHP_VERSION, '5.3.0', '<')) { $mqr=get_magic_quotes_runtime(); set_magic_quotes_runtime(0); } 

1203行:

 if (version_compare(PHP_VERSION, '5.3.0', '<')) { set_magic_quotes_runtime($mqr); } 

由于Magic Quotes现在默认closures(并且计划移除),所以您可以从代码中移除该函数调用。

升级到版本1.6的FPDF。

你不需要用任何东西来代替它。 在PHP6中 ,设置magic_quotes_runtime被删除,所以函数调用是不需要的。 如果你想保持向后兼容性,把它包装在一个if语句中使用version_compare来检查phpversion可能是明智的

 ini_set('magic_quotes_runtime', 0) 

我猜。

Gust在函数前添加前缀“@”为@set_magic_quotes_runtime(0); 在PHP 5.4中不再支持,不要删除或禁用该function

将这些代码添加到脚本的顶部以解决问题

 @set_magic_quotes_runtime(false); ini_set('magic_quotes_runtime', 0);