For beginners, refer to the simple and easy-to-learn PHP course.

Source: Internet
Author: User
PHP is a tool for creating dynamic web pages. The web page embedded in PHP code is like a common HTML file. you can compile it using any of your favorite compilers. What do I need? In this tutorial, assume that your server has been supported

PHP is a tool for creating dynamic web pages. The web page embedded in PHP code is like a common HTML file. you can compile it using any of your favorite compilers.

What do I need?

In this tutorial, assume that your server has supported PHP and all files are named. php3. On most servers, this is the default extended name of the PHP file. you can confirm with your administrator. If your server supports PHP, this is enough. Very simple: create your php file and put it on your server, then the server will handle it wonderfully. You do not need to compile anything or install any additional tools. You can think that the php file is a common HTML file that participates in a set of brand new and wonderful labels.

Your first PHP code

The color of the above code is just a visual help, so that you can easily understand the different parts of PHP labels and expressions. Note that this is not like a CGI program and does not require the executable permission. You can use the php file as an HTML file containing a set of special tags. it can do a lot of things you like.
 
This program is very simple and you do not need to create a WEB page for it. What it does is display: Hello World.

If you have tested this code, but it does not output anything, the title may be that your server does not support PHP. Please ask your administrator to confirm.

The focus of tracing is to introduce PHP labels to you first. Use' 'Tag ends. As shown in the example, you can freely enter and exit the PHP mode in the HTML file.

Something useful

Let's do something more meaningful. If we want to check what the User's browser is, we can check the User Agent string sent by the browser to the WEB server. This information is stored in a variable named $ HTTP_USER_AGNET. The value of this variable can be displayed in a simple way using the following statement:

If you use Internet Explorer, the result may be: Mozilla/4.0 (compatible; MSIE 4.0; Windows 98). In fact, your browser also delivers a lot of other content. Use the following code to obtain a complete list of these variables:

Save this code into a file, such as info. php3, and upload it to your server. open it in a browser. you will see a lot of surprising things. You can place multiple PHP statements in a set of PHP labels, or use a code block to do more. For example, if we want to check whether the browser is MSIE, we can use the following code:

{
Echo 'you are using Internet Explorer.
';
}
?>

Here we will introduce some new things. The first is the "if" statement. If you are familiar with the basic syntax of C language, you can easily understand this code. If you are not familiar with it, it is recommended to find relevant books for reference. PHP retains the simple syntax of C, avoiding the processing of strings and memory that are difficult to control in C language.

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.