Tutorial on getting started with PHP

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

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:
Familiar with HTML, but have no idea about PhP and other dynamic languages, but are using PHP such as dedecms or discuzProgramPerson.
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 <HTML> The corresponding YY in PHP has only one tag. <? PHP?> All things are placed behind PHP.
Row 1: <? PHP
Row 2: PHPCode
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 clipboard Code:

<? $ 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 clipboard Code:

<?
$ 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>



observe the color shown by DW ~ Very useful.
friendship advertisement: the code at the top of the member forum. It can be widely used as an imitation if necessary.

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.