PHP learning: string control course

Source: Internet
Author: User
In which language, string control is an important foundation, which is often simple and important. Just as people speak, they generally have shapes (graphical interfaces) and languages (print strings ?), Obviously, strings can illustrate more things. PHP provides a large supply

In which language, string control is an important foundation, which is often simple and important. Just as people speak, they generally have shapes (graphical interfaces) and languages (print strings ?), Obviously, strings can illustrate more things. PHP provides a large number of string control functions, strong efficacy, application is also relatively simple. the following will briefly describe its efficacy and characteristics.

  Weak type

PHP is a weak type language, so other types of data can be directly used in the string control function, and actively converted to the string type for processing, such:

Echo substr ('20140901', 1, 3 );
And
Echo substr (123456,1, 3 );
Is the same

  Definition

A string is usually identified by double quotation marks or single quotation marks. For example

$ Str = 'I love u ';
$ Str = 'I love u ';

The two have some differences. The latter treats all single quotes as characters; the former is not. For example

$ Test = 'iwind ';
$ Str = 'I love $ test ';
$ Str1 = 'I love $ test ';
Echo $ str; // I love iwind
Echo $ str1; // I love $ test

The actions in the following two examples are different:

Echo 'I love \ test'; // you will get the I love est. \ t is considered as an escape character.
Echo 'I love \ test'; // I love \ test is returned.

In this way, we can simply think that the content in double quotation marks is "explained", and the single quotation marks are "what you see is what you get" (in particular, '\' is regarded as '\'). Obviously, double quotation marks are more mobile. of course, single quotation marks will be used in some special occasions and will not be discussed here.

  Output

The most common output in PHP is echo, print. neither of them is a real function, but a language structure. Therefore, you do not need to use double brackets (such as echo ('test'); print ('test') for calling ')). you can assign values to both outputs:

Echo $ str = 'test'; // outputs test, and assigns test to the string variable $ str.
Print $ str = 'test ';

The two have different names. Print has a returned value and returns 1 for a while echo does not. Therefore, echo is faster than print:

$ Return = print 'test ';
Echo $ return; // output 1

For this reason, print can be used in compound statements, while echo cannot:

Isset ($ str) or print 'Str variable undefined '; // output 'Str variable undefined'
Isset ($ str) or echo 'Str variable undefined '; // An analysis error is prompted.

Echo can output multiple strings at a time, but print cannot:
Echo 'I', 'Love', 'iwind '; // output' I love iwind'
Print 'I', 'Love', 'iwind '; // An error is returned.

Echo and print can also output a string called "document syntax". The syntax is as follows:
Echo <tag name
...
String content
...
Tag name;

For example
Echo <test
I love iwind
Test;

Note that the two label names of the statement start and end are the same, and there cannot be any vacancy before the last label name, that is, the top label should be written. The content of the syntactic output of the document identifies the variable name and common symbols, which is roughly the same as that of double quotation marks.

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.