The content of this section
1.PHP Introduction
2. First PHP script
3.PHP Language Tags
4. Instruction Separator
5. Program Notes
6. Handling of whitespace characters in a program
7. Variables
8. Types of variables
9. Conversion of data types to each other
10. Constants
I. Introduction of PHP
1. What is PHP?
PHP (foreign name: Php:hypertext Preprocessor, Chinese name: "Hypertext Preprocessor") is a common open source scripting language. The grammar absorbs the C language, Java and Perl features, is conducive to learning, widely used, mainly for the field of web development. PHP's unique syntax mixes the syntax of C, Java, Perl, and PHP's own creation. It can execute Dynamic Web pages more quickly than CGI or Perl. Dynamic pages made in PHP are compared to other programming languages, and PHP is executed in HTML (an application under the standard Universal Markup Language), which is much more efficient than CGI, which generates HTML markup entirely; PHP can also execute post-compilation code, Compilation can achieve encryption and optimize code execution, making code run faster.
What can 2.PHP do?
- PHP can generate dynamic page content
- PHP can create, open, read, write, delete, and close files on the server
- PHP can receive form data
- PHP can send and retrieve cookies
- PHP can add, delete, and modify data in a database
- PHP can restrict access to certain pages in the site
- PHP is capable of encrypting data
- With PHP, you can not be limited to outputting HTML only. You can also export images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.
The history of 3.PHP
PHP inherits from an old project called Php/fi. Php/fi was created in 1995 by Rasmus Lerdorf, initially a simple Perl script that tracks the information of people accessing his page. It named this set of scripts "Personal Home Page Tools". As more functional requirements increase, Rasmus writes a larger C language implementation, which can access the database, allowing users to develop simple dynamic WEB programs. Rasmus» released the source code for PHP/FI so everyone can use it, and you can fix it and improve its source code.
Php/fi
PHP/FI, a program that provides an interpreter for your home page/form, already contains some of the basic features of PHP today. It has Perl-style variables, automatically interprets form variables, and can embed HTML. The syntax itself is very similar to Perl, but it is very limited, simple, and somewhat uncoordinated.
PHP/FI 2.0
By 1997, Php/fi 2.0, the second edition of its C language, had thousands of users (estimates) and about 50,000 domain names installed around the world, about 1% of all domain names on the Internet. But then only a few people were writing a small amount of code for the project, and it was still just a human project.
The official version of PHP/FI 2.0 was released in November 1997 after a number of beta releases. Shortly after the release of the first alpha version of PHP 3.0, PHP became successful.
PHP 3
PHP 3.0 is the first version similar to today's PHP syntax structure. Andi Gutmans and Zeev Suraski, when developing e-commerce programs for a university project, found the PHP/FI 2.0 feature was significantly inadequate, and they rewritten the code. This is PHP 3.0. After Andi,rasmus and Zeev a series of efforts, taking into account the Php/fi existing user base, they decided to jointly release PHP 3.0 as the official successor of PHP/FI 2.0. The further development of the PHP/FI 2.0 terminated however nearly.
One of the most powerful features of PHP 3.0 is its extensibility. In addition to providing the infrastructure for the end user with databases, protocols, and APIs, its extensibility also attracts a large number of developers to join and submit new modules. It was later confirmed that this was the key to the great success of PHP 3.0. Other key features in PHP 3.0 include object-oriented support and a more powerful and coordinated syntax structure.
This new language accompanies a new name release. It removes from the name of PHP/FI 2.0 the section that implies "this language is limited to personal use". It is named the simple abbreviation "PHP". This is a recursive abbreviation, its full name is--php:hypertext preprocessor.
By the end of 1998, PHP had installed nearly 10,000 people, with about 100,000 websites reporting that they were using PHP. At the top of PHP 3.0, it was installed on 10% of the Web servers on the Internet.
After about nine months of public testing, the official release of PHP 3.0 was officially launched in June 1998.
PHP 4
In the winter of 1998, shortly after PHP 3.0 was officially released, Andi Gutmans and Zeev Suraski began rewriting PHP code. The design goal is to enhance the performance of the complex program runtime and the modularity of PHP's own code. The new features of PHP 3.0 and the support of a wide range of third-party databases and APIs make it possible to write such programs, but PHP 3.0 does not have the ability to handle such complex programs efficiently.
The new engine, known as the "Zend engine" (the abbreviation for Zeev and Andi), succeeded in achieving the design goals and introduced PHP for the first time in mid-1999. PHP 4.0, which was based on the engine and combined with more new features, was released in May 2000, two years after the release of PHP 3.0. In addition to higher performance, PHP 4.0 includes other key features such as support for more Web servers, HTTP Sessions support, output buffering, more secure methods for handling user input, and some new language constructs.
Today, 10,000 developers (estimates) and millions of Web sites report that PHP is installed, accounting for 20% of the entire Internet domain name.
PHP's development team has a lot of good developers, while there are a lot of good people in the development of PHP-related projects, such as PEAR and PHP documentation works.
PHP 5
PHP 5 released its official version in July 2004 after a long period of development and multiple pre-release versions. Its core is the Zend Engine 2 generation, introducing a new object model and a number of new features.
Two, the first PHP script program
Cases:
<? PHP Print (HelloWorld!.... );? >
Third, PHP language tags
1.xml Style (recommended for standard style)
<? Echo"This is an XML-style tag"
XML-style markup is a common tag and is the recommended tag, and the server cannot be disabled, and the style tag can be used in xml,xhtml.
2. Scripting style
echo' This is a script-style marker '
3. Short style
Note: You need to set short _open_tag=on in php.ini, default is on, or add the –enable-short-tags option when PHP is compiled. (PHP version 3 can also be activated with the Short_tags () function by using the short tag.) )
4.asp style
echo' This is an ASP-style tag '
Note: The default is not supported and needs to be enabled in the php.ini configuration file Asp_tags = on,asp style tag support is added in 3.0.4 version.
The use of short marks should be avoided in the following situations:
Develop programs or libraries that need to be released, or on servers that the user cannot control. Because the target server may not support short tokens. For code porting and distribution, be sure not to use short marks.
Iv. Instruction Separator
Like C or Perl, PHP needs to end the instruction with a semicolon after each statement. An end tag in a PHP code implies a semicolon; the last line in a PHP snippet can end without a semicolon. If there are new rows later, the end tag of the snippet contains the end of the line.
<? PHP Echo "This is a test"; Echo Echo ' We omitted the last closing tag ';
Note: The end tag of the PHP snippet at the end of the file can be omitted, in some cases it would be better to omit it when using include () or require (), so that the unwanted white space does not appear at the end of the file, and the response header can still be output. It is also handy when using output buffering, and you will not see the unwanted white space generated by the include file.
V. Procedural notes
For the person reading the code, the comment is actually the equivalent of the code's explanation and description. Annotations can be used to explain the purpose of the script, the script writer, why to write code in such a way, the time of the last modification, and so on. PHP supports C, C + + and Shell script style annotations, as follows:
// ... ... Single -line comments/ ** /Multiline Comments (Note: cannot be nested)# ... Script Comments
It is a good habit for programmers to use annotations when programming, and the advantages:
Writing Help Documents
Debug program
Note: Note to be written on the top or right of the code
Vi. handling of whitespace characters in programs
In general, whitespace characters (including spaces, tab tabs, line breaks) do not matter in PHP and are ignored by the PHP engine. You can expand a statement to any row, or tighten the statement to a single line. The rational use of spaces and empty lines (by arranging allocations, indenting, etc.) can enhance the clarity and readability of program code, and it will backfire if it is not used rationally. Empty lines are separated by logically related code snippets to improve readability.
1. Two blank lines should always be used in the following situations
- Between two code fragments of a source file.
- Between two declarations of a class
2. A blank line should always be used in the following situations
- Between two function declarations
- Between the local variables within the function and the first statement of the function
- Block comment or line comment before
- Between two logical snippets within a function for improved readability
3. The rules for applying a space can improve readability by indenting the code
- Spaces are generally used between keywords and parentheses, but it is important to note that the function name should not be separated from the opening parenthesis by a space
- Typically insert a space after a comma in a function's argument list
- A space should be added between the operand of a mathematical formula and the operator (except for binary operations and unary operations)
- The expressions in the For statement should be separated by commas, followed by spaces
- The closing parenthesis of a forced type in a type conversion statement should be separated from the expression with a comma, adding a space
Seven, variable
1. Declaration of variables
A variable is a container for temporarily storing values. These values can be numbers, text, or a much more complex permutation combination. is a simple tool for tracking almost all types of information.
PHP is a very weak type of language. In most programming languages, a variable can hold only one type of data, and the type must be declared before the variable is used, such as in the C language. In PHP, the type of the variable is usually not set by the programmer, rather, it is determined by the context at run time (that is, the value of the variable) based on the variable used. PHP does not require a variable to be declared before it is used, and you create it when you assign a variable to it for the first time.
PHP's variable declarations start with a $ character, followed by uppercase and lowercase letters, numbers, and underscores, but cannot start with a number.
<?PHP$a= 100;//declare a variable d to give the integer $b=string”;//declares a variable d, which gives the string string $c=true;//declares a variable D, giving the Boolean value true $d= 99.99;//declare a variable d to give the floating-point number 99.99 $key=$a;//declares a key variable and assigns the value of a variable to the $a=$b=$c=$d= "value";//declare multiple variables at the same time and give the same value?>
Note: You can use the function unset () to release the specified variable, the Isset () function detects whether the variable is set, and the empty () function checks if a variable is empty.
2. Naming of variables
The variable name follows the same rules as other tags in PHP. A valid variable name begins with a letter or underscore, followed by any number of letters, numbers, or underscores. The name of the variable is case-sensitive. However, built-in structures and keywords, as well as user-defined class names and function names, are case insensitive. such as: echo, while, function name, and so on.
<? PHP Echo "This is a test"; Echo "This is a test"; $name="Tarzan"; $Name="Skygao"; Echo $name. $Name // output: Tarzanskygao?>
Viii. Types of variables
1. Type description
Data type:
PHP supports eight primitive types.
four types of scalar :
- Boolean Type (Boolean)
- Integral type (integer)
- Float (float) (floating-point number, also double)
- Strings (String)
Two kinds of composite types:
- Arrays (Array)
- Objects (object)
Finally, there are two special types:
- Resources (Resource)
- Null
In PHP, the type of a variable is usually not set by the programmer, rather, it is determined by the context at run time (that is, the value of the variable) based on the variable used. Use the function var_dump () to view the value and type of an expression.
<?PHP$bool=TRUE;//assigns a Boolean value $str= "Foo";//Assign a string $int= 12;//assign an integer value Var_dump($bool);//output: bool (TRUE) Var_dump($str);//Output: String (3) "Foo" Var_dump($int);//output: Int (+)?>
2. Boolean Type (Boolean)
3. Integral type (integer)
4. Float type (float or double)
5. Strings (String)
6. Arrays (Array)
7. Objects (object)
8. Resource type (Resource)
9.NULL type
10. Pseudo Type Introduction
Cond........
PHP Road, Day1-php Foundation