Home >Backend Development >PHP Tutorial >Solution to error reporting problem using addslashes function in PHP_PHP Tutorial

Solution to error reporting problem using addslashes function in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:13:501115browse

Look at the code below. Can you find the error?

Copy code The code is as follows:

echo function_exists('addcslashes');//Detection Whether this function exists
echo get_magic_quotes_gpc().'
';//Check whether automatic escaping is turned on
echo PHP_VERSION.'
';//php version information
echo addcslashes("Who's John Adams?");
echo '
';
$str = "Who's John Adams?";
echo addslashes($str);
?>

Are the output results the same?
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 reports an error and the other outputs normally. Why?
addslashes and addcslashes are not the same function. I found that there is no difference, only one character.
But the function of both functions is the same—escape strings.
What’s the difference?
addslashes has only one parameter - string
addcslashes requires two parameters, string and delimiter.
echo addcslashes("Who's John Adams?","'"); If you write it like this, you can output it normally. .

Hope it helps everyone understand the usage of addslashes.

Error in addslashes

What a fool, let me show you a code and see if you can find the error?

Copy code The code is as follows:

echo function_exists('addcslashes');//Detect whether the function exists
echo get_magic_quotes_gpc().'
';//Check whether automatic escaping is turned on
echo PHP_VERSION.'
';//php version information
echo addcslashes("Who's John Adams?");
echo '
';
$str = "Who's John Adams?";
echo addslashes($str);

Guess whether the output results are the same? ? ? A: Same B: Still the same
I also think it’s the same, but it’s actually a lie!
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 reports an error and the other outputs normally.

Why?
addslashes and addcslashes are not the same function. I found that there is no difference, only one character.

But the function of both functions is the same—escape strings.
What’s the difference?
addslashes has only one parameter - string
addcslashes requires two parameters, string and delimiter.
echo addcslashes("Who's John Adams?","'"); If you write it like this, you can output it normally. .

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326448.htmlTechArticleLook at the code below, can you find the error? Copy the code The code is as follows: ?php echo function_exists('addcslashes');//Check whether the function exists echo get_magic_quotes_gp...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn