Home > Backend Development > PHP Tutorial > PHP entry-level tutorial: teach you to quickly learn PHP language_PHP tutorial

PHP entry-level tutorial: teach you to quickly learn PHP language_PHP tutorial

WBOY
Release: 2016-07-21 14:56:22
Original
902 people have browsed it

 Bkjia.Com Programming Documentation This article will introduce some PHP entry-level tutorials: Learn PHP quickly.

 PHP syntax.

1. Embedding method:

Similar to ASP's <%, PHP can be . Of course, you can also specify it yourself.

2. Cited documents:

There are two ways to reference files: require and include.
Require is used as require(”MyRequireFile.php”);. This function is usually placed at the front of the PHP program. Before the PHP program is executed, it will first read in the file specified by require and make it a part of the PHP program web page. Commonly used functions can also be introduced into web pages in this way.

 include is used like include(”MyIncludeFile.php”);. This function is generally placed in the processing part of flow control. The PHP program web page only reads the include file when it reads it. In this way, the process of program execution can be simplified.

3. Annotation method:

The following is the quoted content:
以下为引用的内容:
echo “这是第一种例子。n” ; // 本例是 C 语法的注释
/* 本例采用多行的
注释方式 */
echo “这是第二种例子。n” ;

  echo “这是第三种例子。n” ; # 本例使用 UNIX Shell 语法注释
?>

echo "This is the first example. n" ; // This example is a C syntax comment

/* This example uses a multi-line

comment */

echo "This is the second example. n";

以下为引用的内容:
$mystring = “我是字符串” ;
$NewLine = “换行了n” ;
$int1 = 38 ;
$float1 = 1.732 ;
$float2 = 1.4E 2 ;
$MyArray1 = array( “子” , “丑” , “寅” , “卯” );
echo "This is the third example. n" ; # This example uses UNIX Shell syntax annotation

?>

4. Variable type:

The following is the quoted content:
$mystring = "I am a string " ;
$NewLine = "Newline n" ;
$int1 = 38 ;
$float1 = 1.732 ;
$float2 = 1.4E 2 ;
$MyArray1 = array( " " , " Chou " , " Yin " , " Mao " );

Two problems arise here. First, PHP variables start with $, and second, PHP statements end with ;. ASP programmers may not adapt to this. These two omissions are where most errors in the program lie.

5. Operation symbols:


Mathematical operations: Symbol Meaning

以下为引用的内容:
  $a = “PHP 4″ ;
$b = “功能强大” ;
echo $a.$b;
?>
Addition
– Subtraction * Multiplication

/ Division

% Remainder

Accumulation
– Decrement

String operations:

There is only one operator symbol, which is the English period. It can concatenate strings into new merged strings. Similar to &
in ASP

The following is the quoted content:
 $a = “PHP 4″;
$b = “Powerful”;
echo $a.$b;
?>
Two questions arise here. First, the output statement in PHP is echo. Second, it is similar to <%=variable%> in ASP. In PHP, it can also be .

Logical operations:

 Symbol meaning

 < Less than

 > Greater than

 <= Less than or equal to

if (expr) { statement }
 > && And(And)<🎜> and And (And)<🎜> || Or (Or)<🎜> or Or (Or)<🎜> xor > <🎜> PHP process control <🎜> <🎜> 1. If..else loop has three structures <🎜> <🎜> The first one is to only use the if condition and treat it as a simple judgment. Interpreted as "what to do if something happens." The syntax is as follows: <🎜> <🎜> <🎜>

Where expr is the condition for judgment, usually logical operation symbols are used as the condition for judgment. The statement is the execution part of the program that meets the conditions. If the program has only one line, the curly brackets {} can be omitted.

Example: This example omits the curly braces.

以下为烈火建站学院引用的内容:
if ($state==1)echo “哈哈” ;
?>

Special attention here is that the judgment of equality is == instead of =. ASP programmers may often make this mistake, = is assignment.

Example: The execution part of this example has three lines, and the curly brackets cannot be omitted.

以下为引用的内容:
if ($state==1) {
echo “哈哈 ;
echo “
” ;
}
?>

The second type is to add an else condition in addition to if, which can be interpreted as "how to deal with something if something happens, otherwise how to solve it." The syntax is as follows

 if (expr) { statement1 } else { statement2 } Example: Modify the above example into a more complete process. Since there is only one line of instructions for executing else, there is no need to add braces.

以下为引用的内容:
if ($state==1) {
echo “哈哈” ;
echo “
”;
}
else{
echo “呵呵”;
echo “
”;
}
?>

The third type is the recursive if..else loop, which is usually used in various decision-making judgments. It combines several if..else statements for processing.

Look directly at the example below

以下为引用的内容:
if ( $a > $b ) {
echo “a 比 b 大” ;
} elseif ( $a == $b ) {
echo “a 等于 b” ;
} else {
echo “a 比 b 小” ;
}
?>

The above example only uses a two-level if..else loop to compare the two variables a and b. When actually using this kind of recursive if..else loop, please use it with caution, because too many levels of loops can easily cause problems with the design logic, or missing braces, etc., can cause inexplicable problems in the program.

2. There is only one type of for loop with no changes. Its syntax is as follows

 for (expr1; expr2; expr3) { statement }

 where expr1 is the initial value of the condition. expr2 is the condition for judgment, and logical operators are usually used as the condition for judgment. expr3 is the part to be executed after statement is executed. It is used to change the conditions for the next loop judgment, such as adding one, etc. The statement is the execution part of the program that meets the conditions. If the program has only one line, the curly brackets {} can be omitted.

The following example is written using a for loop.

以下为引用的内容:
for ( $i = 1 ; $i <= 10 ; $i ) {
echo “这是第”.$i.”次循环
” ;
}
?>

3. The switch loop usually handles compound conditional judgments. Each sub-condition is part of the case instruction. In practice, if many similar if instructions are used, it can be synthesized 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 is usually a variable name. The exprN after case usually represents the variable value. After the colon is the part to be executed that meets the condition. Be sure to use break to break out of the loop.

以下为引用的内容:
switch ( date ( “D” )) {
case “Mon” :
echo “今天星期一” ;
break;
case “Tue” :
echo “今天星期二” ;
break;
case “Wed” :
echo “今天星期三” ;
break;
case “Thu” :
echo “今天星期四” ;
break;
case “Fri” :
echo “今天星期五” ;
break;
default:
echo “今天放假” ;
break;
}
?>

What needs to be noted here is break; don’t omit it, default, it’s okay to omit it.

Obviously, using the if loop in the above example is very troublesome. Of course, when designing, you should put the conditions with the greatest probability of occurrence at the front and the conditions with the least occurrence at the end, which can increase the execution efficiency of the program. In the above example, since the probability of occurrence is the same every day, there is no need to pay attention to the order of the conditions.

Build database

In ASP, if it is an ACCESS database, you can directly open ACCESS to edit the MDB file. If it is a SQL SERVER, you can open the Enterprise Manager to edit the SQL SERVER database. However, in PHP, the command line editing of MY SQL may It's very troublesome for beginners. It doesn't matter. You can download PHPMYADMIN and install it. You can rely on it to build and edit the database in the future.

Let’s talk about its use below.
After entering phpmyadmin, we first need to create a database. Select Chinese Simplified Language (*) here, then create a new database on the left, fill in the database name here, and click Create.

Then select the created database in the drop-down menu on the left.

below

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

Fill in the table name and the approximate number of fields you think (it doesn’t matter if there are not enough or too many, you can add them later or default them), and press Execute.
Then you can start creating the table.
The first column is the name of the field; the second column selects the field type:
We commonly use the following ones:
1) VARCHAR, text type
2) INT, integer type
3) FLOAT, floating point type
4) DATE, date type
5) You may ask, where is the automatically added ID? Just select the INT type and select auto_increment in the following extras.

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364217.htmlTechArticleLieHuo.Net Programming Document This article will introduce some entry-level PHP tutorials: Learn PHP quickly. PHP syntax. 1. Embedding method: Similar to ASP, PHP can be ?php or...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template