67

当我尝试运行我必须使用但未编写的 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);

如果这是一个不推荐使用的功能,我可以用什么替换它?

非常感谢!

4

11 回答 11

73

先看看有没有开。这应该可以消除警告,并且可以确保如果您的代码在旧版本的 PHP 上运行,魔术引号确实是关闭的。

不要只删除其他人建议的那行代码,除非您可以 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/

于 2010-02-07T19:40:00.977 回答
31

我使用了 FPDF v. 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);
}
于 2011-11-24T09:53:12.167 回答
13

由于 Magic Quotes 现在默认关闭(并在 PHP v8 中删除),您可以从代码中删除该函数调用。

于 2010-02-07T19:27:27.623 回答
6

你不需要用任何东西替换它。magic_quotes_runtimePHP6中删除了该设置,因此不需要函数调用。如果您想保持向后兼容性,最好将其包装在 if 语句中,使用version_compare检查phpversion

于 2010-02-07T19:28:08.660 回答
6

升级到 FPDF 1.6 版。

于 2011-02-25T13:05:11.337 回答
6

在 PHP 7 中,我们可以使用:

ini_set('magic_quotes_runtime', 0);

代替set_magic_quotes_runtime(0);

于 2019-04-24T18:17:14.967 回答
4
ini_set('magic_quotes_runtime', 0)

我猜。

于 2010-02-07T19:30:33.567 回答
2

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

@set_magic_quotes_runtime(false);
ini_set('magic_quotes_runtime', 0);
于 2013-06-08T06:46:08.383 回答
2

阵风在函数前添加前缀“@”为@set_magic_quotes_runtime(0);php 5.4 不再支持,请勿删除或禁用该功能

于 2013-05-23T16:25:37.917 回答
2

我通过注释掉那行代码来修复我的问题,它工作正常。

//if(get_magic_quotes_runtime())
//  @set_magic_quotes_runtime(0);
于 2021-06-22T19:08:22.837 回答
0

更新此功能:

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;
于 2019-01-16T09:45:56.240 回答