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.
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.
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.
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:
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.
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.
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.
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.
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.
<html> <head> <title>HELLO WORLD!</title> </head> <body> <!--以上为普通HTML代码,以下为PHP代码--> <?<span>php </span><span>echo</span> "HELLO WORLD!"; <span>//</span><span>用echo打印字符串</span> ?> <!--以上为PHP代码--> </body> </html>
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.
PHP has three kinds of comments:
Single-line comments: #, //
Multi-line comments: /*some code*/