php introduction
With the rapid development of network technology, various scripting languages for creating dynamic websites based on the server are emerging in endlessly. Among them, PHP is unique among many dynamic website language technologies due to its simplicity, ease of use, and strong portability. So what exactly is PHP and how to use PHP? This chapter will answer these questions. Through studying this chapter, readers will have a general understanding of PHP and learn how to add PHP code to ordinary Web pages.
1.1 About static web pages and dynamic web pages
Currently, there are two types of web pages on the Internet: static web pages and dynamic web pages. Before talking about these two web pages, let's first understand the client (Client) and server (Server) in the network structure. A server is a device that has server software installed and can provide services such as web browsing, database query, etc. to clients. The client, on the other hand, obtains services such as web browsing and software downloading from the server through client software such as a web browser. Simply put, the server is the service provider, and the client is the service recipient.
1.1.1 Traditional static web page HTML
The implementation model of static web pages is as shown in the figure: Static web pages have the following characteristics: Static web pages cannot be automatically updated. The content of static web pages does not change with changes in conditions such as browsing users and browsing time. Once a static web page is published, no matter whether the viewer browses it or not, it is a real file and corresponds to a URL. There are considerable limitations in using static web pages to achieve human-computer interaction.
1.1.2 The difference between dynamic web pages and traditional web pages
Different from the implementation method of static web pages, the implementation process of dynamic web services is as follows: the client applies to the server, and the server processes the internal code of the dynamic web page accordingly on the server according to the user's request, and then sends the generated The results are sent to the client. Its mode is as shown in the figure:
1.1.2 The difference between dynamic web pages and traditional web pages
Dynamic web pages have the following characteristics:
Dynamic web pages run on the server side.
Different people, at different times and in different places browse the same dynamic web page, and different content will be returned based on the code processing results.
A dynamic web page will only return a complete web page when it is browsed by the customer, and it is not a web page file that exists independently on the server.
Compared with static web pages, dynamic web pages are easier to achieve human-computer interaction.
Websites built with dynamic web pages are easier to maintain than static web pages.
1.2 About PHP
The previous section introduced static web pages and dynamic web pages to readers, and PHP is one of the dynamic web page technologies. So what is PHP and what is its development history? Compared with other dynamic web technologies, what are the characteristics of PHP? This section will answer these questions for readers.
1.2.1 What is PHP
In the early days, some people interpreted PHP as Personal Home Page, that is, personal home page. Some people also call PHP: "PHP: Hypertext Preprocessor". In layman's terms, PHP is a server-side, cross-platform scripting language that can be embedded in HTML. The characteristics of server-side execution indicate that it is a type of dynamic web page. Cross-platform means that PHP can run not only on Linux systems but also on UNIX or Windows systems. In addition, it can be easily embedded into ordinary HTML pages. All the user has to do is to add PHP code to ordinary HTML pages.
1.2.2 Development History of PHP
PHP was originally developed in 1994 by Rasmus Lerdorf. In mid-1995, the second version of PHP was released, named PHP/FI (Form Interpreter).
The development plan for the third version started in mid-1997. The development team joined Zeev Suraski and Andi Gutmans, and the third version was named PHP 3.0.
In May 2000, PHP 4.0 was officially released. It uses the Zend (Zeev Andi) engine, which provides higher performance.
In July 2004, PHP 5 came out. The birth of PHP 5 has brought PHP programming into a new era. The adoption of Zend II engine, complete object model, and improved syntax design. Finally, PHP becomes a fully designed scripting language with truly object-oriented capabilities.
1.2.3 Comparison between PHP and other CGI programs
As a server-side programming language, PHP has its own characteristics compared with other CGI programs such as ASP.NET, JSP, etc., which are mainly reflected in the following aspects: Web server support. Running platform support. Scripting languages are different. Database support varies. Object-oriented support is different.
1.3 The first program-HELLO WORLD!
<html> <head> <title>HELLO WORLD!</title> </head> <body> <!--以上为普通HTML代码,以下为PHP代码--> <?php echo "HELLO WORLD!"; //用echo打印字符串 ?> <!--以上为PHP代码--> </body> </html>
1.3.1 Add PHP code to the page
PHP is an embeddable language. In other words, it can be easily added to common HTML pages. When a user requests a PHP file, the relevant PHP code is first interpreted and executed on the server side to generate new HTML information, which is then sent to the user together with the original HTML code.
1.3.2 Add comments to PHP page
PHP has three kinds of comments:
Single line comment: #, //
Multi-line comments: /*some code*/
The above introduces the basics of PHP and PHP basic tutorials. Understanding the above content is the basis for learning PHP. I hope it will be helpful to everyone.