How to solve an error when using the addslashes function in php

Source: Internet
Author: User

Let's look at the following code. Can you find out where the error is?

Copy codeThe Code is as follows: <? Php
Echo function_exists ('addcslashes'); // checks whether the function exists.
Echo get_magic_quotes_gpc (). '<br/>'; // checks 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 );
?>

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 error and the other normal output. Why?
Addslashes and addcslashes are not the same function. They are not found to have only one character.
However, the functions of both functions are the same-escape strings.
What is the difference?
Addslashes only has one parameter-string
Addcslashes requires two parameters: string and delimiter.
Echo addcslashes ("Who's John Adams? "," '"); In this way, the output can be normally written.

I hope to help you understand the usage of addslashes.

Addslashes Error

Sorry, I want to show you a code to see if you can find any errors?

Copy codeThe Code is as follows: echo function_exists ('addcslashes'); // checks whether the function exists.
Echo get_magic_quotes_gpc (). '<br/>'; // checks 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 );

Do you think the output results are the same ??? A: Same B: the same
I also think the same thing, but it's actually a pitfall!
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 and the other normal output.

Why?
Addslashes and addcslashes are not the same function. They are not found to have only one character.

However, the functions of both functions are the same-escape strings.
What is the difference?
Addslashes only has one parameter-string
Addcslashes requires two parameters: string and delimiter.
Echo addcslashes ("Who's John Adams ?"," '"); In this way, the output can be normally written.

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.