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

Jul 21, 2016 pm 02:56 PM
php introduce getting Started study college Build a website fast teach you Tutorial document programming language

 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles