PHP Basic Syntax Summary _php instance

Source: Internet
Author: User
Tags comments define function html tags php language phpinfo

One, what can PHP do?

What can PHP do? I think it is very strong, as long as I can think of, it can do, but my technical ability is not enough (╯﹏╰) ╭. Well, a picture, a basic understanding of it (ps:php function is not limited to this (^_^))

The image is a little blurry, make it up, (≧▽≦)/

Second, PHP language tags

1, end and start tag

1.1 <?php//code: is an XML style, is the standard style of PHP, recommended use.

1.2 <script language= "PHP" >//code </script>: Long style tags, not commonly used. If your wonderful editor doesn't support other PHP tags, use it.

1.3;? Code: Short style, follow SGML processing. You need to open the instruction Short_open_tag in php.ini, or add –enable-short-tags when PHP compiles. If you want your program to migrate well, discard this style, it's less than 1.1 PHP.

2, location

What do you say? Anyway, you can place the PHP language anywhere in the HTML file with the suffix. php. Note that the HTML file ends with. php.

Copy Code code as follows:

1: 2: 3: <meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" >
4: <!--embed script in HTML tags-->
5: <title><?php echo "PHP language Tag"?></title>
6: 7: <!--embedding--> in attribute position
8: <body <?php echo ' bgcolor= "#ccc" '?>>
9: <!--a higher order,-->.
Ten: <?php
11:if ($exp) {
A:?>
< embedding PHP--> in property values!--
<p align= "<?php Echo ' center '?>" > condition is True </p>
: <?php
:}else{
:?>
<p> condition is false </p>
: <?php
20:}
:?>
</body>
:

3, Notes

3.1 Single-line Comment:///# Multiline Comment:/* Description * *

More than 3.2 lines of comments cannot be nested, but they can contain single-line comments, and single-line comments can contain multiple lines of comments. Just like that.

Copy Code code as follows:

1: <?php
2://echo "Test";/* Single line contains multiline comment * *
3:/*echo ' Test '; Multiple-line comment contains a single-line annotation character.
4:?>

Third, variable

1, the use of variables

Copy Code code as follows:

1: <?php
2: $a = 1; Declare a variable A
3: $b = "PHP"; Declaring a variable b
4: $8d = 2; Illegal variable name that starts with a letter or an underscore and does not contain spaces
5:
6: $i site is = "PHP"; Legal variable name, you can use the Chinese
7:/*
8: * The following three functions are called in the way equivalent
9: * keywords and built-in functions and user-defined class names, function names are not case-sensitive
10: */
11:phpinfo ();
12:phpinfo ();
13:phpinfo ();
14:
15:
16:/*
17: * The following three variables are not the same
18: * Variable name is case-sensitive
19: */
$name = "PHP1";
$Name = "PhP2";
$NAME = "PhP3";
23:
24://variable variable: Variable name can be set dynamically
$hi = "Hello";
: $ $hi = "World";
27://below all output Hello World
28:echo "$hi $hello";
29:echo "$hi ${$hi}";
30:
31://Variable Assignment
$foo = "B"//value Assignment
A: $bar = & $foo//reference assignment
A: $bar = "LZ";
35:echo "$foo"; Output LZ
A: $CDE = $foo; Transfer value Assignment
Panax Notoginseng: $cde = "E";
38:echo "$foo"; Output LZ
?>:

2, the type of the variable

Four, constant

1. Definition and use

Copy Code code as follows:

1: <?php
2:/*
3: *boolean define (String name,mixed value[,bool case_insensitive)
4: *name: constant name; value: constant value; Third is an optional Boolean value, the default is False (case-insensitive)
5: */
6:define ("FLO", 1000);
7:echo FLO; Output 1000
8:
9://Use the Define function to verify the existence of Flo constants, and to output constant values
10:if (define ("FLO"))
11: {
12:echo FLO;
13:}
:?>

2, constants and variables

The scope of the 2.1 constant is global, and you can declare and access constants anywhere in the script.

2.2 Constants are not preceded by $, and constants cannot be defined by assignment statements.

2.3 Constants, once defined, cannot be redefined or undefined until the end of the script is automatically released.

The value of a 2.4 constant can only be a scalar (a type in boolean,integer,float,string)

3, the system's predefined constants

4, the Common magic constants

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.