PHP Entry-level tutorial: teach you how to quickly learn PHP language _php Tutorials

Source: Internet
Author: User
Tags learn php switch loop
   Fire Station College (bkjia.com) programming document This article to introduce somePHP Entry-level tutorial: Learn PHP quickly.

  PHP's syntax.

1. Embedding Method:

An ASP-like <%,php can be , of course, you can specify it yourself.

2. Reference file:

There are two ways to refer to a file: Require and include.
Require use methods such as require ("myrequirefile.php");. This function is usually placed at the front of the PHP program, and before the PHP program executes, it is read into the file specified by require to make it a part of the PHP program's Web page. Commonly used functions, you can also use this method to introduce it into the Web page.

Include usage methods such as include ("myincludefile.php");. This function is usually placed in the processing part of the process control. The PHP Program page reads the include file before it is read in. This way, you can simplify the process when the program executes.

3. Annotation method:

The following is the referenced content:
echo "This is the first example. n "; This example is a comment for C syntax
/* This example uses multiple lines of
Comment Method */
echo "This is the second example. n ";

echo "This is the third example. n "; # This example uses UNIX Shell syntax annotations
?>

4. Variable type:

The following is the referenced content:
$mystring = "I am a string";
$NewLine = "NewLine n";
$int 1 = 38;
$float 1 = 1.732;
$float 2 = 1.4E 2;
$MyArray 1 = Array ("Child", "ugly", "Yin", "Mao");

This leads to two problems, first the PHP variable begins with $, the second PHP statement ends, and the ASP programmer may not be able to adapt. These two omissions are also the most procedural errors.

5, Operation symbols:

Mathematical operations: symbolic meanings
Addition operation
-Subtraction operation
* Multiplication operation
/Division Operation
% take remainder
Accumulation
– Decrement

String Operations:

The arithmetic symbol has only one, is the English period. It can concatenate strings together and become merged new strings. & In ASP-like

The following is the referenced content:
$a = "PHP 4″;
$b = "powerful";
echo $a. $b;
?>


Here also leads to two problems, first of all, the output statement in PHP is Echo, the second similar to ASP in the <%= variable%>,php can also 。

Logical operation:

Symbolic meaning
< less than
> Greater than
<= less than or equal to
>= greater than or equal to
= = equals
! = does not equal
&& (and)
And and (and)
|| or (OR)
or or (or)
XOR (XOR)
! No (not)

Process Control in PHP

1. If: else loop has three types of structure

The first is to use the IF condition as a mere judgment. Explain how to deal with something if it happens. The syntax is as follows:

  

if (expr) {statement}

The conditions in which expr is judged are usually determined by the use of logical operation symbols. And statement is a qualifying execution part of the program, if the program has only one row, you can omit the curly brace {}.

Example: This example omits curly braces.

  

The following is a quote from the fire Station Academy:
if ($state ==1) echo "haha";
?>

It is particularly important to note that determining whether equality is = = rather than =,asp programmers can often make this error, = is an assignment.

Example: The execution section of this example has three rows and cannot omit curly braces.

  

The following is the referenced content:
if ($state ==1) {
echo "haha;
echo "
” ;
}
?>

The first two is the addition of the IF condition, which can be interpreted as "what to do if something happens or how to resolve it". The syntax is as follows

if (expr) {statement1} else {Statement2} example: the example above is modified to a more complete processing. The else in which there is only one line of instructions, so do not add braces.

The following is the referenced content:
if ($state ==1) {
echo "haha";
echo "
”;
}
else{
echo "hehe";
echo "
”;
}
?>

The third type is recursive if. else loops, often used in a variety of decision-making judgments. It will be a few if. Else to combine the use of processing.

Look directly at the following example

The following is the referenced content:
if ($a > $b) {
echo "A is larger than B";
} elseif ($a = = $b) {
echo "a equals B";
} else {
echo "A is smaller than B";
}
?>

The above example uses only two layers of if. else loop, which is used to compare the two variables of a and B. This recursive if is actually to be used. else loop, please be careful to use, because too many layers of the loop is easy to make the logic of the design problems, or less curly braces, etc., will cause the program to appear inexplicable problem.

2, for the loop is only one, no change, its syntax is as follows

for (EXPR1; expr2; expr3) {statement}

Where the EXPR1 is the initial value of the condition. EXPR2 is a condition for judging, usually using the logic operation symbol (logical operators) when judging the condition. EXPR3 the part to be executed after the execution of the statement, to change the condition for the next cycle judgment, such as add one. Wait a minute. And statement is a qualifying execution part of the program, if the program has only one row, you can omit the curly brace {}.

The following example is an example written with a for loop.

The following is the referenced content:
for ($i = 1; $i <=; $i) {
echo "This is the first". $i. " Secondary cycle
” ;
}
?>

3, switch loop, usually deal with the conditional judgment of the compound, each sub-condition, is the case instruction part. In practice, if you use many similar if directives, you can combine them into a switch loop.

The syntax is as follows

Switch (expr) {case expr1:statement1, break, Case Expr2:statement2, break, DEFAULT:STATEMENTN, break;}

The expr condition, which is usually the variable name. The ExprN after a case usually represents the value of the variable. The colon is followed by the part that meets the criteria to be executed. Note to use break to jump off the loop.

The following is the referenced content:
Switch (date ("D")) {
Case "Mon":
echo "Today Monday";
Break
Case "Tue":
echo "Today Tuesday";
Break
Case "Wed":
echo "Today Wednesday";
Break
Case "Thu":
echo "Today Thursday";
Break
Case "Fri":
echo "Today Friday";
Break
Default
echo "Holiday Today";
Break
}
?>

Here is the break; don't miss it, default, omitting is possible.

Obviously, the above example is very troublesome with the IF loop. Of course, in the design, the most likely to be the highest probability of the conditions at the front, the least occurrence of the conditions on the last side, you can increase the efficiency of the execution of the program. The previous example has the same probability of appearing every day, so don't pay attention to the order of the conditions.

Building a Database

In ASP, if you are an Access database you can directly open access to edit the MDB file, if it is SQL Server you can open Enterprise Manager to edit the SQL Server database, but in PHP, MY SQL command-line editing may make beginners feel very troublesome, It doesn't matter, you download a phpmyadmin to install, and later build the editing database can rely on it.

Let's talk about its use.
After entering the phpMyAdmin, we first need to establish a database, Language (*) Here to select Chinese Simplified, and then on the left to create a new database here to fill in the database name, click Create.

Then select the database that you have created in the left drop-down menu. In the following

Create a new table in the database shop:
Name:
Number of fields:

Fill in the table name and roughly what you think of the number of fields (not enough or more of it does not matter, can be added later or default), press to execute.
Then you can start building the table.
The first column is the name of the field; the second column selects the field type:
The following are some of our common uses:
1) VARCHAR, text type
2) INT, integer type
3) Float, floating-point type
4) Date, type
5) You may ask, where is the auto-added ID? As long as you select the int type, you can select Auto_increment in the additional options below.

    • Total 3 Pages:
    • Previous page
    • 1
    • 2
    • 3
    • Next page

http://www.bkjia.com/PHPjc/364217.html www.bkjia.com true http://www.bkjia.com/PHPjc/364217.html techarticle Fire Station College (liehuo.net) Programming Document This article describes some of the PHP entry-level tutorials: learn PHP quickly. PHP's syntax. 1, embedding method: Similar to ASP%,php can be PHP or ...

  • 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.