Getting Started with PHP

Source: Internet
Author: User
Tags getting started with php learn php

Recently, the company recruit a few fresh graduates, they know a lot about the front end, but the technology of the back end of ignorance, I think, as a front-end siege Lion, if you have lofty aspirations, you should rain equitably ...

Today, I'll tell you about PHP's most basic introduction, at least people ask you to come, not a little do not understand.

We know that PHP build environment is very troublesome, we front-end siege lion does not need to delve into the environment of the building, the Internet has an integrated PHP environment can be directly downloaded, Wamp and Phpstudy (click into the download page), install just the next line.

Because I have been using Wamp, a bit of wamp as an example to explain.

This icon appears in the lower right corner of the screen when the Wamp is installed.

If your English is not very good, you can right-click the icon and select Chinese.

When Wamp is turned on, all services are turned on by default, you can also left-click the icon, select Start all services, and switch to online status .

Here, the PHP environment is ready to run.

Here's how to start the demo.

Click on the lower right corner of the small icon, there is a www directory, enter after the creation of a project called PHP folder:

Create these files in the folder:

Let's start by opening login.html and writing a simple form:

1<!DOCTYPE html>2<HtmlLang= "en">3<Head>4<MetaCharSet= "UTF-8">5<Title>document</Title>6</Head>7<Body>8<FormAction= "success.php"Method= "POST">9 User name:<InputType= "Text"Name= "username"><Br/><Br/>10 Password:<InputType= "Password"Name= "PWD"><Br/><br/>11 <input type = "submit"  Name= "Submit" Span style= "COLOR: #ff0000" > Value= "submit" >12 </form >13 </body>14 </html>   

The effect is as follows:

We need to implement the user click Submit, the user entered the user name and password saved in the local data.txt file, and the success.php page prompts the user to log on successfully.

Let's start with the key PHP code, open the success.php file, and typing the following code:

1 <! DOCTYPE html>2 3 4 <meta charset= "UTF-8" >5 <title>Document</title>6 7 <body>8 <?Php9$name =$_post["username"];10$pwd =$_post["PWD"];11$FP =fopen ("./data.txt", "a"12  $STR = "User:".  $pwd. " \ r \ n "; fwrite ( $fp,  $str 14 fclose ( $fp 15 echo " $name. "! ; >17 </body>18    

It should be noted that the PHP code can be mixed with HTML code, wrapped in <?php dosomething?> tags within the code, the server will use the PHP parser to parse, let us analyze the above code.

Because the form is submitted using post, we need to use post to receive, PHP receive post sent over the data using $_post[""; Statement, get usage, change post to get, fill in the brackets with the name of the table item you want to get.

Next we will write the resulting data into the Data.txt file, which is written to the database in the actual project development.

We use the fopen command to open a file, fopen receive two parameters, the first is to open the path of the file, the second is opened in a way, where the "A" is written to open, the file pointer to the end of the file, if the file does not exist, it will attempt to create this file. (For details of other parameters, see W3school)

It is also important to note that the variable declarations in PHP are not Var, but $+ variable names.

Next the user name and password into a string, PHP string splicing and JavaScript are also different, PHP use "." To make the concatenation character.

We use the fwrite command to write to the file, it receives two parameters, the first is to open the file, that is, the $fp we defined earlier, the second is to write the contents of the previously spliced string into.

Finally, you need to close the file and use the fclose command to pass in the file that needs to be closed. If you do not close the file, the file will always be occupied, others will not be able to read and write this file, so this step must not forget.

Finally, I output a message in the Success.php page, JavaScript can use document.write to output content, PHP uses echo statement to output content, support input HTML tags.

Here, a simple Php_demo is written, let's test it.

In the browser input http://localhost/php/login.html Enter the page, we randomly enter some information:

After submission, the page jumps to success.php and we see the following:

We open the Data.txt file to see if the data is written.

It is true that we have written the data in the format we specified, and I'll try to log in several times:

Test success!

Hope you follow the above code to knock over, you will find a sense of accomplishment, at least when I first learn PHP to complete this demo, the excitement broke me.

Of course, this is just the simplest example of PHP, over a period of time to write how to use PHP to read and write data MySQL article, I hope you keep a curiosity to technology, so as to truly grow!

Finally attach the project source: easyphp (or hope you can knock)

Reproduced in: http://www.cnblogs.com/chinajins/p/5622342.html

Getting Started with PHP

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.