Php: string data type instance details

Source: Internet
Author: User
A string is a continuous character sequence consisting of numbers, letters, and symbols. Each character in a string occupies only one byte. In PHP, there are three methods to define strings: single quotes (), double quotes ("), and delimiters (& lt ;). What is a string )?

A string is a continuous character sequence consisting of numbers, letters, and symbols. Each character in a string occupies only one byte.

In PHP, there are three methods to define strings: single quotation marks ('), double quotation marks ("), and delimiters (<).

Single quotation marks and double quotation marks are often used to define strings. they are defined as follows:

Single quotes

 

Double quotation marks

 

The difference between single quotes and double quotes is that variables contained in double quotes are automatically replaced with actual values, while variables contained in single quotes are output based on common characters, what does this mean? let's look at the example below

Examples of the differences between single quotes and double quotes defining strings

 "; // Output short Mark echo '$ I'; // output in single quotes?>

The sample running result is as follows:

One thing to note here is that \ n and \ r are no different in Windows systems and can all be used as carriage returns. But in Linux, there are two effects. in Linux, \ n indicates switching to the next line, but it does not return to the first line; while \ r indicates that the cursor returns to the first line, however, if you are using a Linux operating system, try again.

If we use "\" for non-escape characters, "\" will be output along with the output.

When defining some simple strings, using single quotes is a better way to handle them. If double quotation marks are used, PHP will take some time to process string transfer and variable parsing. Therefore, when defining a string without special requirements, we 'd better use single quotation marks.

Identifier

The identifier <) is supported from PHP4.0. The end string is the same as the end string. The format of the delimiter is as follows:

$ String = <str string to be output

Str indicates the specified identifier.

Delimiter example

The code is as follows:

 \ $ I content: $ istd?>

Code running result:

The end identifier must start with another line and cannot contain spaces. There are other characters or symbols before and after the identifier, and a system error may also occur, including comments.

In the next section, we will introduce "integer" in the scalar data type )".

The above is php: detailed description of the string data type instance. For more information, see other related articles in the first PHP community!

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.