1 Basic PHP syntax

Source: Internet
Author: User

PHP tags

1 when parsing a file, PHP looks for the start and end tags, that is, <?php and, and any parts outside the start and end tags will be ignored by the PHP parser.

2 PHP also allows the use of short mark <? And, but not encouraged to use. Short marks can be used only by activating the Short_open_tag configuration directive in php.ini or by using the configuration option--enable-short-tags when compiling PHP.

3 If the file content is pure PHP code, it is best to remove the PHP end tag at the end of the file. This avoids having to accidentally add a space or line break after the PHP end tag, causing PHP to start outputting these blanks, and there is no intent to output at this time in the script.

<?phpecho "Hello World";


Detach from HTML

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

<p>html content </p><?= "Hello world";? ><p>html content </p>


Four pairs of different start and end tags

1 <?php?> is always available

<?php Echo ' Hello world ';?>

2 <script language= "PHP" > </script> always available

<script language= "php" >echo ' Hello World ';</script>



3 short mark. The directive Short_open_tag in the PHP.ini configuration file is available only after it is opened, or the--enable-short-tags option is added when PHP is compiled.

<?php $HW = "Hello world";? ><? echo $hw; ><?= $hw;? >

4 ASP style tag. It is only available after the instruction Asp_tags in the php.ini configuration file is opened (usually deprecated).
<?php $HW = "Hello World";?>
<% Echo $HW; %>
<%= $HW%>

Attention:
1 because the server may not support short tags. for porting and distributing code, make sure that you do not use short tags.
2 PHP 5.2 and previous versions, the interpreter does not allow the entire contents of a file to be a start tag <?php. This file is allowed from PHP 5.3, but there is one or more white space characters after the start tag.
3 from PHP 5.4, the short-form echo tag <?= is always recognized and valid, regardless of the Short_open_tag setting.

Instruction delimiter:
The end tag in the 11-segment PHP code implicitly represents a directive delimiter: semicolon.
2 The last line in a PHP code snippet can end without a semicolon.
3 The last line is omitted, the semicolon cannot be omitted.

<?phpecho "Hello World";//semicolon? ><?php echo "Hello World"//omit semicolon? ><?php echo ' Hello World ';//cannot omit


Comments:

1 Basic PHP syntax

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.