A tutorial network PHP introductory tutorial 03:php syntax structure

Source: Internet
Author: User
Tags comments php file

I. PHP syntax structure

PHP's syntax structure is divided into four styles: Standard style, short style, ASP style, long style.

1. Standard style

This is the most used of a style;

The writing format is:

<?php

Code snippet;

?>

Note: The PHP end of each sentence with a semicolon!

Example:

<?php

echo ' Hello World '

?>

Build Method: Here to the standard style as an example to illustrate, after writing code, see the effect of the method, the following styles also apply.

The first step: Open the Phpstudy folder → Open the www folder → create a new folder, named Demo!

Step Two: Run Zend Studio, right click in the left margin, select "new" → "Project";

Step three: Click Local PHP Project to create a new file

The fourth step: in the shot out of the box, input and small part of the same thing, the file name is named "Day1", save the directory for the previous set up a good "Demo", the last click Finish;

Fifth Step: Enter the above for everyone to write good example code, ctrl+s save the file;

Sixth step: Open the browser, in the browser input "localhost", if the display and the following picture is not the same, then look at the seventh step, if the same click "Demo" → "Day1" to see the code generation effect.

Seventh step: In Phpstudy, click on the other Options menu →phpstudy settings → allow directory listing, and finally back to the browser refresh will become the same as the sixth step.

2. Short style

Writing format:

?

Code snippet;

?>

Note: you need to Short_open_tag = on in the PHP configuration file, restart the server to take effect;

Detailed steps:

The first step: Open Phpstudy, click "Other Options Menu" → "Open configuration file" → "Php-ini", as shown in the following figure;

The second step: Press the shortcut key "Ctrl+f", Input: Short_open_tag, click Down Search, find the location of the following figure, the "off" to "on", if it is on, then do not move it.

The third step: click on the phpstudy on the restart can be.

Example:

?

Echo ' Welcome to Cloud Community Network '

?>

3, ASP style

The writing format is:

<%

Code snippet;

%>

Note: Need PHP configuration file Asp_tags = On, restart the server in effect, this everyone reference short style can;

Example:

<%

Acho ' Welcome to cloud-dwelling community network '

%>

4, long style

Writing format:



Example:



Second, PHP comments

PHP annotations are divided into single-line comments and multiline annotations;

Reasons to write comments: to be able to work with colleagues or small partners, others or themselves can clearly understand the role of the Code.

1. Single note

Use '//' to annotate, as shown below;

<?php

//This is our single-line comment.

Echo ' Welcome to Cloud Community Network '

?>

2, Multiline comments

Use/**/to annotate, as follows:

<?php

/*

* This is our multiline comment.

* */

Echo ' Welcome to Cloud Community Network '

?>

Three, PHP file naming Considerations

1. Start with letters or underscores, followed by numbers, letters and underscores;

2, the name should have the meaning, a see the file name to know inside content;

3, do not include special characters;

4, do not have Chinese;

The above is this time for everyone to bring the grammar structure of the entire content of PHP, I hope you can have a harvest after reading.

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.