PHP

The solution to the error reporting problem in php using the addslashes function


If you look at the code below, can you see where the error is?

<?php
echo function_exists('addcslashes');// Detects the existence of the function
echo get_magic_quotes_gpc().'<br/>';// Detects whether automatic escape is enabled
echo PHP_VERSION.'<br/>';//php Version information
echo addcslashes("Who's John Adams?");
echo '<br/>';
$str = "Who's John Adams?";
echo addslashes($str);
?>

Does the output look like 1? 10 5.3.6 Warning: addcslashes() expects exactly 2 parameters, 1 given in /data/bookuu/test/class.php on line 50 Who\‘s John Adams?

One reported an error, and the other one was output normally. Why is that? addslashes and addcslashes are not the same as a function, found no, only a character difference. But both functions do the same thing — escape a string. What’s the difference? addslashes has only one argument - a string addcslashes requires two parameters, a string and a separator. echo addcslashes (” Who ‘s John Adams?” , ”’”); So I can write it like this and I can output it normally.

I hope that helps you understand the use of addslashes.

addslashes mistake

I’m going to show you a code to see if you can find any errors.

echo function_exists('addcslashes');// Detects the existence of the function
echo get_magic_quotes_gpc().'<br/>';// Detects whether automatic escape is enabled
echo PHP_VERSION.'<br/>';//php Version information
echo addcslashes("Who's John Adams?");
echo '<br/>';
$str = "Who's John Adams?";
echo addslashes($str);

Can you guess if the output is 1?? A: one. B: one I also think 1 kind of but, actually pit father! 10 5.3.6

Warning: addcslashes() expects exactly 2 parameters, 1 given in /data/bookuu/test/class.php on line 50

Who’s John Adams?

One reported an error, and the other one was output normally.

Why? addslashes and addcslashes are not the same as 1 function, found no, only 1 character difference.

But both functions do the same thing — escape a string. What’s the difference? addslashes has only one argument - a string addcslashes requires two parameters, a string and a separator. echo addcslashes (” Who ‘s John Adams?” , ”’”); So I can write it like this and I can output it normally.