Getting started with PHP. NET

Source: Internet
Author: User
Tags getting started with php
PHP. NET is a tool for creating dynamic web pages. A webpage embedded with PHP code is like a common HTML file. you can use any editor you like to edit it. The object described in this tutorial is PHP3.0. what do I need? In this tutorial, assume that your server has been "> <LINKhref =" http: // PHP is a tool for creating dynamic web pages. A webpage embedded with PHP code is like a common HTML file. you can use any editor you like to edit it. The object described in this tutorial is PHP 3.0.

What do I need? In this tutorial, assume that your server already supports PHP and all files use. php3 as the extension. On most servers, this is the default PHP file extension. you can confirm with your administrator. If your server supports PHP, this is enough. It is easy to create your php file and put it on your server, then the server will skillfully process it. You do not need to compile anything or install any additional tools. You can think like this: PHP files are common HTML files with a new set of clever labels.

The color of your first PHP code above is just a visual help, making it easier for you to understand the different parts of PHP labels and expressions. Note that this is not like a CGI program and does not require executable permissions. You can use the php file as an HTML file containing a set of special tags. it can do a lot of things you are interested in.
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 tried this code but it does not output anything, the problem may be that your server does not support PHP. Ask your administrator to confirm.
Refer focuses on introducing PHP labels to you. Use" "The tag ends. As shown in the example, you can freely enter and exit the PHP mode in the HTML file.

Something useful allows us to 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. you can use the following statement to easily display the value of this variable:

If you are using Internet Explorer, the result may be: Mozilla/4.0 (compatible; MSIE 4.0; Windows 98). In fact, your browser also delivers many 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, you are advised to find some reference books. PHP retains C's simple syntax, avoiding the processing of strings and memory that are difficult to control in C.
Second, we call a function: strstr (). Strstr () is a PHP built-in function used to find another string in a string. In this example, we find "MSIE" in the variable $ HTTP_USER_AGENT. if we find the font string, the function returns the TRUE value, that is, TRUE. Otherwise, the function returns the opposite value.
Next let's take a look at how to enter and exit the PHP mode, even in the middle of a PHP code block:
If (strstr ($ HTTP_USER_AGENT, "MSIE ")){
?>
You are using Internet Explorer
} Else {
?>
You are not using Internet Explorer
}?>
The method of outputting HTML code directly in PHP mode instead of echo statements. It is very important that the logic integrity of php code cannot be damaged. The result displayed when running this code may be:
You are using Internet Explorer

Another powerful aspect of processing form PHP is processing forms in html files. To understand this basic concept, all elements of the HTML file form are automatically transmitted to the target page with the same name. This seems a bit difficult to understand. we will illustrate this through the following example:



This form only contains the necessary HTML tags and is incomplete. When the user fills out the form and presses the "Submit" button, the file action. php3 is called. Assume that this file contains the following code:

Hi . You are Years old.

The execution result is obvious because the variables $ name and $ age are automatically set by PHP.

More? This tutorial may be further expanded, so far.
For other tutorials, see:

WebMonkey

DevShed

PhpTidbits

PHPBuilder.com

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.