Summary of PHP basic syntax and PHP basic syntax

Source: Internet
Author: User
Tags define function php book

Summary of PHP basic syntax and PHP basic syntax

I. What can PHP do?

What can PHP do? I think it is very powerful, as long as I can think of it, it can be done, but my technical capabilities are not enough. Okay, let's take a look at the figure. (ps: PHP functions are not limited to this (pai_^ ))

The image is a bit blurred )/

 

Ii. PHP language mark

1. End and start mark

1.1 <? Php // code?> : It belongs to the xml style and is a standard PHP style. It is recommended.

1.2 <script language = "php"> // code </script>: long style mark, not commonly used. If your wonderful editor does not support other php tags, use it.

1.3 <? // Code?> : The short style follows SGML processing. In php. in ini, open the command short_open_tag, or add-enable-short-tags during php compilation. if you want your program to be portable, You can discard this style, and it is less than 1.1 php.

2. Location

What should I do? You can put the PHP language anywhere in the HTML file suffixed with. php. Note: it is an HTML file ending with. php.

   1: 
   2:     
   3:         <meta http-equiv="content-type" content="text/html;charset=utf-8">
4: <! -- Embed scripts in HTML tags -->
5: <title> <? Php echo "PHP language mark"?> </Title>
   6:     
7: <! -- Embed data in the attribute position -->
   8:     <body <?php echo 'bgcolor="#ccc"'?>>
9: <! -- Come to an advanced level -->
  10:         <?php
  11:             if($exp){
  12:         ?>
13: <! -- Embed php in the property value -->
14: <p align = "<? Php echo 'center'?> "> The condition is true. </p>
  15:         <?php
  16:             }else{
  17:         ?>
18: <p> the condition is FALSE. </p>
  19:         <?php
  20:             }
  21:         ?>
  22:     </body>
  23: 

3. Notes

3.1 single line comment: // or # multi-line comment:/* Description */

More than 3.2 line comments cannot be nested, but can contain single line comments; single line comments can also contain multiple lines of comments. Just like this

   1: <?php
2: // echo "test";/* a single line contains multiple line annotators */
3:/* echo 'test'; // contains a single-line annotator */
   4: ?>

 

Iii. Variables

1. Use of Variables

   1: <?php
2: $ a = 1; // declare a variable
3: $ B = "php"; // declare a variable B
4: $ 8d = 2; // invalid variable name. It can only start with a letter or underline and does not contain spaces
   5:
6: $ I site is = "php"; // valid variable name, which can be in Chinese
   7:     /*
8: * The following three function call methods are equivalent.
9: * keywords and built-in functions and user-defined class names. The function names are case-insensitive.
  10:      */
  11:     phpinfo();
  12:     PhpInfo();
  13:     PHPINFO();
  14:
  15:
  16:     /*
17: * The following three variables are different.
18: * variable names are case sensitive
  19:      */
  20:     $name = "php1";
  21:     $Name = "php2";
  22:     $NAME = "php3";
  23:
24: // variable: variable names can be dynamically set
  25:     $hi = "hello";
  26:     $$hi = "world";
27: // hello world is output below
  28:     echo "$hi $hello";
  29:     echo "$hi ${$hi}";
  30:
31: // variable assignment
32: $ foo = "B" // value assignment
33: $ bar = & $ foo // reference value assignment
  34:     $bar = "LZ";
35: echo "$ foo"; // output LZ
36: $ cde = $ foo; // value assignment
  37:     $cde = "E";
38: echo "$ foo"; // output LZ
  39: ?>

2. Variable type

 

Iv. Constants

1. Define and use

   1: <?php
   2:     /*
   3:      *boolean define(string name,mixed value[,bool case_insensitive)
4: * name: constant name; value: constant value; the third value is an optional Boolean value. The default value is FALSE (Case Insensitive)
   5:      */
   6:     define("FLO",1000);
7: echo FLO; // output 1000
   8:
9: // use the define function to check whether a FLO constant exists. If yes, the constant value is output.
  10:     if(define("FLO"))
  11:     {
  12:         echo FLO;
  13:     }
  14: ?>

2. constants and variables

2.1 The scope of a constant is global. You can declare and access a constant anywhere in the script.

2.2 There is no $ before a constant, and a constant cannot be defined using a value assignment statement.

2.3 Once a constant is defined, it cannot be redefined or canceled until the script stops running.

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

3. predefined constants of the system

4. Common magic Constants


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


Basic php syntax

Double quotation marks are used to output strings. Example: echo "data insertion failed, error message: <br> ";
And "insert into testtable VALUES ('". $ xm. "',". $ nl. ")"; in insert into testtable VALUES is a string, which means to INSERT to the database, two "" are a group, put. $ xm. separated ,(. $ xm .) $ xm is a variable. echo is used when a variable is displayed in php.

The basic syntax of php and database has been basically mastered. How can I recommend a php book with a complete project ?? I really want to learn php well

PHP and MySQL Web development: the "php Bible". In comparison, "PHP with zero Infrastructure" is more suitable for beginners. It is easy to see that the author writes it with heart.
This book is actually one of the zero basic programming series, and others are quite good.
The content is well designed. There is a preface, which is very pertinent. It is the advice that programmers give to cainiao. The excerpt is as follows:
++ ++
Notes for learning programming:
1. do not stick to the Syntax: Many beginners try to memorize various syntaxes. In fact, this is extremely wrong. The syntax and norms of program development are too many to remember. You only need to know that such a function is available. yes, you can read books or search for help files when necessary, which saves time and effort.
2. Multi-handed and multi-exercise: people who only know books will not become masters of development. Only by writing programs on multiple computers can they improve their understanding of programming in practice.
3. if you encounter a problem, first try to solve it by yourself: if you try your best to solve it at the first time, you cannot find help again. Do not immediately seek help if you encounter any problem, which will never improve much.
4. Google and Baidu: The network is a large knowledge base and the best teacher. If you have any problems or other people have encountered them, search for them.
4. Read the source code of others more: Read the design ideas of others and continue to use them.
++ ++
The disadvantage of this book is that there is no line mark in front of the Code, while a large mistake is made when "xxx line," is widely used in the interpretation of the Code.

Summary: in terms of knowledge points, "no basic learning PHP" may be incomplete. However, what we need is not a dictionary. We need a well-intentioned book that we are interested in learning, isn't it?

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.