The difference between single and double quotes in PHP _php tutorial

Source: Internet
Author: User
In a programming language, either single quotation marksStill is Double quotes, all have a very important role in PHPLanguage is the same. Compared to ASP, PHP quotation marks better use, in ASP, to put the data into the variable must be enclosed in double quotation marks, and in the case of the use of quotation marks can only be used in single quotes, not double quotation marks, if the use of double quotation marks will be used as the end of the previous quotation mark.

However, there is no such restriction in PHP. Substituting variables, single and double quotes can be used, but in pairs.

In PHP, there is no difference between single and double quotes if you are only using text-type data that does not contain variables. But if you want to use a variable, the single and double quotes are different.

In PHP, double quotes can be used to directly substitute variables, without the need for a definition or other symbols,

Such as:

 
  
  
  1. $b = "Cat"; $a $b"; //Display This is a cat

Single quotes are not, if

 
  
  
  1. $a$b'; //is displayed as: This is a $b.

In the operational efficiency of the single quotation mark and double quotation marks are also different, in general, single quotation marks will run faster, double quotation marks are slower, because the double quotation marks to find whether there are variables in the statement, and single quotation marks are not used, so if there is no substitute variable in the statement as far as possible single quotation marks. This is a habit of writing programs, always thinking about improving the efficiency of the program.

If you want to define an action in a statement, you must use double quotation marks.

For example, when you go to define single quotes, write this:

 
  
  
  1. $a

The program will show the he's name is Tom intact, if this is written:

 
  
  
  1. $a

The program will show: He's name is Tom.

Single quotation marks are stumbling blocks to SQL statements, and text data in SQL statements is enclosed in single quotes, so if single quotes appear in the data, the database considers the data to end, then the subsequent data is considered to be the other parts of the SQL statement, which of course will be an error when querying the database. So text-based data written into SQL statements must be addslashes () to define single quotes, and then use Stripslashes () to turn back when reading the data.


http://www.bkjia.com/PHPjc/445808.html www.bkjia.com true http://www.bkjia.com/PHPjc/445808.html techarticle In a programming language, both single and double quotes are important, as is the case in the PHP language. Compared with ASP, PHP quotes better use, in ASP, to the data generation ...

  • Related Article

    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.