How can I replace the deprecated set_magic_quotes_runtime in php?


Php Problem Overview

I'm getting this message when I try to run a php script I have to use but did not write.

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:


If this is a deprecated function, what can I replace it with?

Thank you very much!

Php Solutions

Solution 1 - Php

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.

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.

// Check if magic_quotes_runtime is active
    // Deactivate

get_magic_quotes_runtime is NOT deprecated in PHP 5.3.

Solution 2 - Php

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:

Line 1164:

if (version_compare(PHP_VERSION, '5.3.0', '<')) {

Line 1203:

if (version_compare(PHP_VERSION, '5.3.0', '<')) {

Solution 3 - Php

Since Magic Quotes is now off by default (and removed in PHP v8), you can just remove that function call from your code.

Solution 4 - Php

You don't need to replace it with anything. The setting magic_quotes_runtime is removed in PHP6 so the function call is unneeded. If you want to maintain backwards compatibility it may be wise to wrap it in a if statement checking phpversion using version_compare

Solution 5 - Php

Upgrade to version 1.6 of FPDF.

Solution 6 - Php

In PHP 7 we can use:

ini_set('magic_quotes_runtime', 0);

instead of set_magic_quotes_runtime(0);

Solution 7 - Php

ini_set('magic_quotes_runtime', 0)

I guess.

Solution 8 - Php

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

Solution 9 - Php

add these code into the top of your script to solve problem

ini_set('magic_quotes_runtime', 0);

Solution 10 - Php

I fixed mine by removing that line of code by commenting them out and it worked fine.

//	@set_magic_quotes_runtime(0);

Solution 11 - Php

Update this function :

if (version_compare(PHP_VERSION, '5.3.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);
if ($magic_quotes) {
  if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  else {
    ini_set('magic_quotes_runtime', $magic_quotes);

return $file_buffer;


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShawnView Question on Stackoverflow
Solution 1 - PhpphilfreoView Answer on Stackoverflow
Solution 2 - PhptestingView Answer on Stackoverflow
Solution 3 - PhpDoug T.View Answer on Stackoverflow
Solution 4 - PhpYacobyView Answer on Stackoverflow
Solution 5 - PhpMartinView Answer on Stackoverflow
Solution 6 - PhpRAMIL T.KView Answer on Stackoverflow
Solution 7 - Phpuser187291View Answer on Stackoverflow
Solution 8 - PhpAlaa SadikView Answer on Stackoverflow
Solution 9 - PhpSomwang SouksavatdView Answer on Stackoverflow
Solution 10 - PhpMoses SamanhyiaView Answer on Stackoverflow
Solution 11 - PhpPraveen KumarView Answer on Stackoverflow