Tutorial on getting started with PHP

Source: Internet
Author: User
Tags getting started with php mysql functions

The PHP system can contain 32678 bytes in length. In addition to punctuation, the PHP system can contain 10 thousand characters. If it is full, it will not be short....
In line with the principle of simplicity and smoothness, which is suitable for the vast majority of impetuous MJJ users to browse, I try to streamline and effectively describe the PHP learning path.

This article is suitable for the audience:
Proficient in HTML, but ignorant of PHP and other dynamic languages, but still using php programs such as dedecms or discuz.
Of course, you also need to be interested in learning PHP. After all, even if it is simple, you also need the motivation to learn. Interest is undoubtedly the best.
If you are not familiar with computer operations, absolute paths, and relative paths, please go to Mars.

Prerequisites:
Attitude:Be conscientious, careful, and not impetuous.
Time:It only takes two hours.But pay attention to the full time of two hours. do not take the time to do anything else, because when learning is interrupted, it is inevitable to look back, And I am writing for top PHP non-professional writers, it is impossible to systematically teach, once interrupted, I will try again later. so please prepare for two hours. I try to make this article give you some access to PHP within two hours.
Environment setup: ① Single-host; ② integrated environment suitable for cainiao; ③ recommended software: APMServDownloadAddress (PHP version 5.2.0)
To prevent the establishment of a super new employee in the environment from getting stuck, I first posted a tutorial on setting up an environment with APMServ. Click here to view details.

FAQs before getting started

Q: Can I become a master in two hours?
A: tu: Come with me YY ,《Learn PHPThe goal is to simply learn PHP! You can only get a general idea of PHP in two hours and have a deep learning foundation. please do not have fantasies, be down-to-earth, and step by step to win. after reading this article, even if you cannot become a master, you will also take a step towards the master ..
Q: What editor or something should I use?
A: In this tutorial, we only use Macromedia Dreamweaver 8. The editor is not an excellent product. The text can be used as A webpage!
Q: Are you talking too much...
A: ELE. Me, start now.
-------------------------------------

================ Shameless split line ================

Meal 1:
One:Iconic Language
The The corresponding YY in php has only one tag. <? Php?> All things are placed behind php.
Row 1: <? Php
Row 2: A piece of PHP code
Row 3:?>
All <? Php can be replaced with <? Saving "php "~~~
Self-built projects:
DW new, dynamic page, PHP, code mode, delete all content, and then enter <? Php?> And <?>, Then press enter and delete the key several times to experience the red virgins! In just a few minutes, I started writing PHP ~ Awesome, Master ~

Two:Simplest output
The miser may have typed something in the above "a little PHP code" position, and then saved it and opened it for a look, blank or even wrong...
Because PHP is not html of course, it is the server language. The so-called server language is that you open this page, and then the server parses the page into html according to the rule and returns it to you. A server parsing process is more than html.
Try the following code:
<?
Echo'Smile for dinnerHandsome'
?>
Save the file name as yy. php is enabled. If the default prefix suffix is PHP, it must be enabled in a PHP-enabled environment. if you encounter problems here, check whether APMServ is enabled and whether the file you saved is stored in www \ htdocs under the APMServ directory. if all are correct, check whether the browser address is http: // 127.0.0.1: Port/yy. php

Three:Most Common Errors
Modify the code above:
<?
Echo 'smile and have a nice meal'
Echo 'really handsome'
?>
Will there be an error after saving and opening it? This is the most common and most common php error in history.
Php is parsed line by line. Note the understanding of "line". ";" must be added at the end of each line. Is the right of the letter L.
I am also puzzled. what's even more annoying is that there is no error correction function and it cannot be opened when an error occurs. Fortunately, the error will show the row where the error is located.

Four:The most important concepts
After the code above is added as ";", it will show the effect of "smile, eat, handsome, really handsome" sticking together.
Right-click the source file and you will find that the original source file is also like this. What should we do?
Php is a language that can insert html, that is, it can drop html to QJ...
Theoretically<? No matter how long?>Can be inserted into html... Copy the following to try it out...
 

<Html>  

 

 

Five:The most important application
If you haven't moved your hands yet, take a few minutes, but there is an important experience.
People who have done this seriously will find that PHP is a waste of learning? So now... I can't tell you how to use the variable here.
I try to use as few terms as possible, but the variable cannot find a substitute. But let's take a look.
<?
$ Chifan = "123er ";
Echo $ chifan;
?>
After saving and opening, the displayed content is 123er, so it is easy to think about modifying the Code if you are familiar with html.""Between 123er can modify the display content!
There is no error, and theoretically modify two chifan, as long as they are the same, they can also be displayed.
There are only two rows. The first row defines the value of the variable chifan as 123er, and the second row displays the variable chifan. That's simple.
It is easy to learn how to define variables and display variables!

Dinner 2:
After simple, interesting, and vivid learning in "Eat one", do you think PHP is actually not difficult at all? But are you also beginning to worry that PHP is useless?
This section details the concept of php.
Obviously, the previous article is not vivid. This section is not necessary. You can skip this section if you just want to know something and don't want to learn it. R/>Php functions:What is a function? For example, if y = 2x is a function, you only need to know x to obtain the corresponding y. php's powerful function library is one of its major tough functions. For example, for mysql functions, you only need the database name, username, and password to connect to the database freely and simply.
Php Manual: records the tokens of php syntax and functions, because not everyone can remember every Syntax of every function. therefore, most people need to query the manual when using it. it makes a simple analogy, such as the Function y = 2x. If you don't know this function, You have to calculate it as x + x, but if you know that there is a function y = 2x, you just need to call the Function y and input x to get the result. for the php manual, it is recommended that you read the manual once and once again. Do not remember but remember what functions are provided in the Manual. maybe you can write x + x on your own, but you may not write it more complex, the more troublesome the problem is, the more obvious and necessary it is to call a ready-made function.
You can write functions by yourself. functions have such powerful functions and meanings, but they always have their own unique needs. functions can be written by yourself. Good at using functions can achieve twice the result with half the effort ...... So much nonsense is about understanding the function, so we can see how important the function is!
The last recommended or understandable analogy is that some practical functions such as time call functions and IP address retrieval functions can be found in the Manual, you can easily obtain the time and IP address you want to customize by simply calling the function to display the result. (I don't know)
Face the object and face the process: Ask Baidu or GG to get off the question... Simple theme.
Syntax details:
For example: <? Echo "Haha"?> <? Echo 'haha '?> (Where is the difference? In""And") And the difference between the full angle and the half angle. "" ''() and how to display" "the things that define variables and other headaches !... I have a headache when I think of it. It must be a headache when I see it.
There is no difference between fullwidth and halfwidth. The functions are the same. It is perfect.
It is not difficult to display the syntax symbols. You only need to add a slash (/) before the corresponding symbol, but it looks awkward.
The difference between dual-cited and single-cited is that the dual-cited will parse the variables, and the single-cited will be directly displayed.
<?
$ Mjj = "Haha ";
Echo $ mjj;
Echo "<br> ";
Echo "this is $ mjj ";
Echo "<br> ";
Echo 'this is $ mjj ';
?>
The following three are a small supplement to common syntaxes.
Constant: define
<? Php
Define ("PAGE_TITLE", "MJJ page ");
Define ("PAGE_BODY", "MJJ is a chicken ");
?>
<Html>
<Title> <? Php echo PAGE_TITLE?> </Title>
<Body>
<? Php echo PAGE_BODY?>
</Body>
</Html>
Simpler output <? ==>
If the above title sentence can be changed:
<Title> <? = PAGE_TITLE?> </Title>
Call require and include on the page
Both are called other pages. php is translated line by line, but require is called first, and include is translated when reading this line.
How to Use the call is a great art. (for fear of errors, you can use require_once to only call this page once) The format is as follows:
Require_once './include/286. php ';
Include 'mjj. php ';
Create a 286. php or mjj. php file by yourself. It can be written as a txt file, but it must comply with the php syntax.

Meal 3:
Instance:A line of URL jump code

Copy content to clipboardCode:

<? $url=$_GET["url"];header("Location:"."http://".$url);?>

For example, if you save it as aaa. php, You can implement aaa. php? Url = www.baidu.com jump to Baidu.
This simple call of the default $ _ GET variable. and php default jump Location:
(More default variables are available in the manual)
Instance upgrade:Add if Loop

Copy content to clipboardCode:

<?
$ Url = $ _ GET ["url"];
If (strlen ($ url> = '3 ')){
Header ("Location:". "http: //". $ url );
}
?>
<Html>
<Head>
<Title> URL redirection page </title>
</Head>
<Body>
<Form id = "url" name = "url" method = "get" action = "#">
<Label> http ://
<Input name = "url" type = "text" value = ""/>
</Label>
<Input type = "submit" name = "Submit" value = "submit"/>
</Form>
</Body>
</Html>

After talking about so many things, we haven't talked about the loop. It's the most difficult content of this tutorial. (It's easy to show off how easy a post is to learn ~)
The upgrade code is very simple, that is, the jump page can also be opened, when the get url address is greater than 3, the jump.

After learning:
If you are inspired to learn PHP and feel that you are already getting started (you can check it again before getting started ),Two advanced methods.
For example, you can read the php manual again first, and then start to find the message book, blog, BBS (sequence, text can be followed by mysql) instance to start re-production step by step.
If you are passionate about it, you can start looking for an instance and start following the instance step by step. If you feel that you are lacking, you can add the php manual. There are too many instances on the network.
Improvement stage:Understand the changes and differences between php4, php5, and php6. this article focuses on the popular php programs. (You need to adapt to an editor before. If you have better understanding of a framework, the outdated forum has released a framework. See the code section .) the open-source php program will bring you a new experience. If you understand it later, you should at least understand it.
Advanced Stage:I am not qualified for the introduction. I hope you will become a master.
Finally, I wish all friends interested in php could become masters!

------------- Split line ---------
Finally, the vulnerability is not ruled out. This article takes more than 4 hours and 3 hours in total, hoping to help friends in need.

 

<Div style = "background-color: #606096; height: 6px; font-size: 0px;"> </div>
<Div style = "height: 24px; padding: 3px 10px 0px 0px; text-align: right; background: # F1F1F1;">

<?
Echo 'smile at dinner ';
Echo 'really handsome ';
?>

</Div>

</Body>
</Html>
Observe the color shown by DW ~ Very useful.
Friendly advertisement: this effect is the code at the top of the forum, which can be widely used for imitation.

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.