Home  >  Article  >  Backend Development  >  PHP string definition methods and their differences

PHP string definition methods and their differences

不言
不言Original
2018-05-02 11:01:092087browse

This article mainly introduces the definition methods of PHP strings and their differences. It has certain reference value. Now I share it with you. Friends in need can refer to it

  • Single quotes:

## Single quotes cannot parse variables

Single quotes cannot parse escape characters, they can only parse single quotes and backslashes themselves


You can use

. to connect variables and variables, variables and strings, and strings and strings

  • # Double quotation marks

This dual quotation can resolve variables, variables can use special characters and {} contain

dual quotation marks to analyze all transfers Characters


Variables and variables, variables and strings, strings and strings can be connected using

.

$sql = "select * from user where name = '{$name}'";-->select * from user where name = 'lisi'


$ sql = 'select * from user where name = \''.$name.'\''; //More efficient

  • The difference between single quotes and double quotes

# Single quotation number is higher than the double quotes

## The function is similar to the double quotes


#

$str = <<<EODExample of string
spanning multiple lines
using heredoc syntax.
EOD;
$str = <<<"FOOBAR"Hello World!FOOBAR;

There cannot be any other symbols before the end identifier (indentation is not allowed)

  • nowdoc

Function is similar to single quotes

$str = <<<&#39;EOD&#39;Example of string
spanning multiple lines
using nowdoc syntax.
EOD;

  • ##Both are used to process large text

  • Related recommendations:

Explanation of PHP string to array and array to string functions




The above is the detailed content of PHP string definition methods and their differences. For more information, please follow other related articles on the PHP Chinese website!

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