PHP string definition methods and their differences

不言
Release: 2023-03-25 08:24:01
Original
2098 people have browsed it

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;
Copy after login

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;
Copy after login

  • ##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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!