Three ways to represent strings in PHP

Source: Internet
Author: User
This article mainly introduces the three kinds of expressions of strings in PHP, the Friends of interest, I hope to help you.

(1) using single quotation marks
The escape character in single quotation marks can only be: \ \, \ '
(2) Use double quotation marks
In double quotes, all escape characters can be used. such as: \ \, \ ', \ ', \$, \ n, \ r, \ t
(3) How to represent a long string
Long string representation, must be placed in "<<"<<"Heredoc;" Must be the end of the tag. Must be a single line and the head is written.
Heredoc can customize the name.
PHP variables can be parsed directly.

Considerations for Strings
1. Within double quotes, the output is the value of the variable. For example: Echo "{$name} is 24 years old"
2. Within single quotes, the output is the name of the variable, not the value.
3, in double quotation marks, if a variable name followed by a non-null character, it will make the compiler confused. The solution is that the following can be followed by a space, or with the English punctuation (special characters), which will parse the variables. The usual method is to add a brace, {$name}

<! DOCTYPE html>  <HTML>   <HEAD>    <TITLE> New Document </TITLE>    <meta name= "Generator" content= "EditPlus" >    <meta name= "Author" content= "" >    <meta name= "Keywords" content= " ">    <meta name=" Description "content=" ">    <style type=" Text/css ">    </style>    <script type= "Text/javascript" >    </script>   </HEAD>     <BODY>    <?php    $name = "Zhang San";    $age =24;    $str =<<

Related recommendations:

PHP long String definition method

How MySQL gets the value after a special character in a variable length string (from StackOverflow)

Example of a PHP long string (here Document) Definition method

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.