Home > Backend Development > PHP Tutorial > Detailed explanation of php reference string constant method

Detailed explanation of php reference string constant method

WBOY
Release: 2016-07-25 08:54:00
Original
1403 people have browsed it
  1. $name = 'yutuo';
  2. // Single quote string
  3. echo 'my name is $name';
  4. // Single quote string
  5. echo "my name is $name" ;
  6. echo "my name is {$name}";
  7. // heredocstring
  8. echo <<< end
  9. my name is $name
  10. my name is {$name}
  11. end;
Copy the code

The result is (the output does not have any line breaks, for ease of understanding, line breaks are included in the results): my name is $name my name is yutuo my name is yutuo my name is yutuo my name is yutuo

The three definition methods of single quotation marks, double quotation marks and the here document from the unix shell are introduced below.

1, single quoted string A single-quoted string refers to a string enclosed in single quotes. It only supports two escape characters, backslash () and single quote (‘), which are represented by (\) and (’) respectively. It should be noted that single-quoted strings do not support (n) line breaks, but single-quoted strings can be defined across lines. The following code: echo 'my name is yutuo. i am studing php.'; The result is (the output has newlines): my name is yutuo. i am studing php.

2, double quoted string A double-quoted string refers to a string enclosed in double quotes. It only supports multiple escape characters and can also be defined across lines. The book says there are curly brackets and square brackets, but when I tested it under PHP 5.3.1, there were none. The list of escape characters for its branches is as follows:

" Double quotes n new line r Enter t tab character \ backslash $ dollar sign
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