Solution to the problem of using addslashes function in PHP _php tips

Source: Internet
Author: User

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

Copy Code code as follows:

<?php
echo function_exists (' addcslashes ');//detect if the function exists
Echo GET_MAGIC_QUOTES_GPC (). ' <br/> '//detect whether to turn on automatic escape
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 result 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 error, another normal output. Why, then?
Addslashes and addcslashes are not the same function, found no, only one character difference.
But the function of two functions is the same-the escape string.
What's the difference?
Addslashes only one argument-string
Addcslashes requires two parameters, strings, delimiters.
Echo Addcslashes ("Who's John Adams", "'") so that it can be written out normally.

I hope to help you understand the usage of addslashes.

Addslashes's mistake.

Hang dad, show us a code to see if you can find errors?

Copy Code code as follows:

echo function_exists (' addcslashes ');//detect if the function exists
Echo GET_MAGIC_QUOTES_GPC (). ' <br/> '//detect whether to turn on automatic escape
echo php_version. ' <br/> ';//php version information
Echo addcslashes ("Who ' s John Adams");
Echo ' <br/> ';
$str = "Who ' s John Adams?";
echo addslashes ($STR);

Everyone guess the output is not the same??? A: Same as B: still the same
I also think the same but, in fact, pit Dad!
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 error, another normal output.

Why?
Addslashes and addcslashes are not the same function, found no, only one character difference.

But the function of two functions is the same-the escape string.
What is the difference?
Addslashes only one argument-string
Addcslashes requires two arguments, strings, delimiters.
Echo Addcslashes ("Who's John Adams", "'") so that it can be written out normally.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.