PHP Introductory Basic Grammar _php tutorial

Source: Internet
Author: User
Tags closing tag
1, separating from HTML

Anything outside a pair of start and end tags is ignored by the PHP parser, which allows the PHP file to have mixed content. You can embed PHP in an HTML document, as shown in the following example.

This was going to being ignored by PHP and displayed by the browser.



This would also is ignored by PHP and displayed by the browser.

This will run as expected, because when the PHP interpreter encounters the?> end tag, it simply outputs the contents as it is (unless immediately following the newline-see instruction delimiter) until the next start tag is encountered;
The exception is in the middle of the conditional statement, at which point the PHP interpreter determines which output to skip, depending on the condition.

See the following example, notice if and else after: colon

Use conditional structure:

This would show if the expression is true.

Otherwise this'll show.


In the example above, PHP skips a paragraph not reached by the conditional statement, even if the paragraph is outside the PHP start and end tags.
Since the PHP interpreter will skip the block of conditional statements directly when the condition is not reached (:?> jumps out of PHP mode and returns the HTML schema), PHP will ignore it based on the condition.
To output large pieces of text, jumping out of PHP parsing mode is usually more efficient than passing text through the Echo or print output.

GetData ())):?>






--------------------------------------------------------------------------------

2, Instruction Delimiter

An end tag in a PHP code implicitly represents a semicolon
The last line in a PHP snippet can end without a semicolon
If there are new rows later, the end tag of the snippet contains the end of the line.
echo "This is a test";
?>

Note:

The end tag of the PHP snippet at the end of the file can not

In some cases it is better to omit it when using include or require, so that unwanted whitespace characters do not appear at the end of the file, and the response headers can still be output.
It is also handy when using output buffering, and you will not see unexpected whitespace characters generated by the include file.


342432353

Otherwise this'll show.

Or


342432353

Otherwise this'll show.


--------------------------------------------------------------------------------

PHP comments

echo "This is a test"; This is a one-line C + + style Comment
/* This was a multi line comment
Yet another line of comment * *
echo "This is yet another test";
Echo ' one Final Test '; # This is a one-line shell-style comment
?>


A single-line comment only comments to the end of the line or the current PHP code block, depending on which first appears.

This means that in//...? > or # ...? The HTML code after > will be displayed.
:?> jump out of PHP mode and return to HTML mode,//or # does not affect this.


C-style annotations end when they hit the first */.
/*
echo "This is a test"; /* This comment'll cause a problem */

*/

Echo ' Kdfjal ';
?>
Will error, output blank


--------------------------------------------------------------------------------
String strings

A string of strings consists of a series of characters, each of which is equal to one byte. This means that PHP can only support 256=2 's 8-party character set and therefore does not support Unicode. See detailed string types.

The note:string can reach 2GB maximum.

Grammar

A string can be expressed in 4 different ways:

Single quotation marks
Double quotes
HEREDOC syntax structure
NOWDOC syntax structure (since PHP 5.3.0)


--------------------------------------------------------------------------------
Single quotation marks

The simplest way to define a string is to enclose it in single quotation marks (characters ').

To express a single quotation mark itself, you need to escape it by adding a backslash (\) in front of it.
To express a backslash itself, use two backslashes (\ \).
Any other backslash is treated as a backslash itself: that is, if you want to use a different escape sequence such as \ r or \ n, it does not represent any special meaning, it is simply the two characters themselves.

Note: Unlike double quotes and HEREDOC syntax structures, the escape sequences of variables and special characters in single-quote strings will not be replaced.

Echo ' This was a simple string ';

Multiple lines can be entered
Echo ' can also has embedded newlines in
Strings this, as it is
Okay to do ';

Output: Arnold once said: "I ll be back"
Echo ' Arnold once said: "I\ ' ll be back" ';

Output: you deleted c:\*.*?
Echo ' you deleted c:\\*.*? ';

Output: you deleted c:\*.*?
Echo ' you deleted c:\*.*? ';

Output: This would not expand: \ n A newline
Echo ' This would not expand: \ n a newline ';

Output: Variables do not $expand $either
Echo ' Variables does not $expand $either ';
?>

--------------------------------------------------------------------------------
Double quotes

If the string is enclosed in double quotation marks ("), PHP will parse some special characters:
Escape character

Sequence meaning
\ nthe newline (LF or 0x0A (10) in the ASCII character set)
\ r Enter (CR or 0x0D (13) in the ASCII character set)
\ t Horizontal tab (HT or 0x09 (9) in the ASCII character set)
\v Vertical tab (VT or 0x0B (11) in the ASCII character set) (since PHP 5.2.5)
\e Escape (ESC or 0x1B (27) in the ASCII character set) (since PHP 5.4.0)
\f (FF or 0x0C (12) in the ASCII character set) (since PHP 5.2.5)
\ \ Backslash
\$ Dollar Mark
\ "Double quotation marks
\[0-7]{1,3} matches the regular expression sequence with a character that is expressed in eight binary ways
\x[0-9a-fa-f]{1,2} matches the regular expression sequence with a character that is expressed in 16 binary ways

As with single-quote strings, escaping any other character causes backslashes to be displayed. Before PHP 5.1.1, the backslash in the \{$var} was not displayed.

The most important feature of a string defined in double quotation marks is that the variable is parsed, as described in variable parsing.


--------------------------------------------------------------------------------

Heredoc structure

The third way to express strings is to use the HEREDOC syntactic structure:<<<. After the operator, provide an identifier, and then wrap the line. This is followed by the string itself, and finally with the identifier defined earlier as the end flag.

The identifier referenced at the end must be in the first column of the row, and the name of the identifier follows the rules of PHP like any other label: it can only contain letters, numbers, and underscores, and must begin with a letter and an underscore.

http://www.bkjia.com/PHPjc/477459.html www.bkjia.com true http://www.bkjia.com/PHPjc/477459.html techarticle 1, separating from HTML anything that is outside a pair of start and end tags is ignored by the PHP parser, which allows the PHP file to have mixed content. Allows PHP to be embedded in HTML ...

  • 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.