Summary of basic PHP syntax

Source: Internet
Author: User
Tags define function php language phpinfo

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 ╮ (╯﹏╰) ╭. OK, a picture, basic understanding (ps:php function is not limited to this (^_^))

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

Second, PHP language tag

1. End and start tag

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

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

1.3 <? Code: Short style, followed by SGML processing. You need to open the directive Short_open_tag in php.ini, or add –enable-short-tags when PHP is compiled. If you want your program to be good transplant, discard this style, it is 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 named. php. Note that the HTML file ends in. php.

   1: 
   2:     
   3:         <meta http-equiv="Content-type" content="Text/html;charset=utf-8" >  
   4:         <!--embed script in HTML tags --
   5:         "PHP language tag"?></title>
   6:     
   7:         <!--embedded in attribute position --
   8:     ' bgcolor= ' #ccc "'?>>
   9:         <!--to a premium point--
  Ten:         <?php
  One:             if ($exp) {
  :         ?>
  :         <!--attribute values are embedded in PHP --
  :         <p align="<?php Echo ' center '?>" > condition is true </p> 
  :         <?php
  :             }else{ 
  :         ?>
  :         The <p> condition is false </p>
  :         <?php
  :             }
  £         ?>
  :     </body>
  : 

3. Comments

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

3.2 Multiline comments cannot be nested, but they can contain single-line comments, and single-line comments can contain multiple lines of comments. That's what it looks like.

   1: <?php
   2:     //echo "Test";/* contains multiline comment in single line * /
   3:     /*echo ' test ';//A multiline comment character contains a single-line comment */
   4: ?>

Third, variable

1, the use of variables

   1: <?php
   2:     $a = 1;   //Declare a variable a 
   3:     "PHP";  //Declare a variable b 
   4:     $8d = 2;    //illegal variable name, can only start with a letter or underscore and does not contain spaces 
   5:
   6:     //Legal variable name, can be used in Chinese
   7:/     *
   8:    * The following three function call methods are equivalent
   9:    * keywords and built-in functions and user-defined class names, function names are case-insensitive
  Ten:     * /
  One:     phpinfo ();
  :     PhpInfo ();
  :     PHPINFO ();
  14:
  15:
  :/     *
  :    * The following three variables are not the same
      * Variable name is case-sensitive drop
       * /
  :     "PHP1";
  :     "PhP2";
  :     "php3";
  23:
  Variable     variable: variable name can be set dynamically
  :     "Hello";
  :     "World";
       Output Hello World below://
  :     "$hi $hello";
  :     "$hi ${$hi}";
  30:
  :     //variable assignment
  :     "B"  //value assignment 
  :     //reference Assignment
  :     "LZ";
       "$foo";  //Output LZ 
  *:     $cde = $foo;  //Transfer value Assignment 
  Panax Notoginseng:     "E";
  :     "$foo";  //Output LZ 
  : ?>

2. Types of variables

Iv. Constants

1. Definition and use

   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, default is False ( case insensitive)
   5:     * /
   6:     define ("FLO", +); 
   7:     echo FLO;          //Output 
   8:
   9:     //Use the Define function to verify that the Flo constant exists, and that the output constant value exists
  :     if (define ("FLO")) 
  One:     {
  :         echo FLO;
  :     }
  : ?>

2. Constants and variables

The scope of the 2.1 constant is global, and the constants can be declared and accessed anywhere else in the script.

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

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

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

3. Predefined constants of the system

4. Common Magic Constants


Source: http://www.ido321.com/510.html

Summary of 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.