Below with everyone into the PHP entry path Description:
I am here temporarily Apache Web server and MY SQL as a WEB server and database, under php-4.3.3 environment to do the program. Of course, to build a simple visit and visit PHPMYADMIN essential database Here need to understand the basics of HTML! No HTML basics! You can go to Baidu or GOOGLE search! Very simple! Not much to say here, let's get started! Let's start with PHP as an apple! Ate him!
Not long-winded! Started to eat an apple
1, embedded method:
Similar to the ASP <%, PHP can be either <? Php or <?, the end symbol is?>, Of course, you can also specify their own.
2, reference documents:
There are two ways to reference a file: require and include.
require the use of methods such as require ("MyRequireFile.php");. This function is usually placed at the very beginning of the PHP program. Before the PHP program executes, it will read the file specified by the require file and make it a part of the PHP program web page. Commonly used functions, this method can also be introduced into the web page.
include using methods like include ("MyIncludeFile.php");. This function is generally placed in the process control part of the process. PHP program page read include file, it read it in. This way, you can simplify the process when the program is executed.
3, annotation method:
<? php
echo "This is the first example."; // This example is a comment on C ++ syntax (the PHP comment is about the same as C!)
/ * This example uses multi-line comment * /
echo "This is the second example."
echo "This is the third example."; # This example uses the UNIX Shell syntax comment
?>
4, variable type:
$ mystring = "I am a string";
$ NewLine = "newline";
$ int1 = 38;
$ float1 = 1.732;
$ float2 = 1.4E + 2;
$ MyArray1 = array ("sub", "ugly", "yin", "d");
Here leads to two problems, first of all PHP variables beginning with $, the second PHP statement ending; ASP programmers may not adapt. These two omissions are also the most procedural errors.
5, operator symbol:
Number ** illegal words have been shielded ** count:
Symbolic meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Take the remainder
++ cumulative
- decremented
String operations:
There is only one arithmetic symbol, which is the full stop of English. It can concatenate strings into new strings that are merged. Similar ASP &
<?
$ a = "PHP 4";
$ b = "Powerful";
echo $ a. $ b;
?>
Here also leads to two questions, first of all PHP output statement is echo, the second is similar to ASP <% = variable%>, PHP can also <? = Variable?>.
logic operation:
Symbolic meaning
<Less than
> Greater than
<= Less than or equal to
> = Greater than or equal to
== equal to
! = Not equal to
&& And (And)
And (And)
|| Or (Or)
or or (Or)
xor XOR (Xor)
Not (Not)
Talk about process control
Learning Objectives: Grasp the PHP process control
1, if..else cycle has three structures
The first is only used if conditions, as a simple judge. Explain "what happens if something happens." Grammar is as follows:
if (expr) {statement}
Which expr judgment conditions, usually used when the logic operator to determine the conditions. The statement for the implementation of the part of the program is eligible, if the program has only one line, you can omit the braces {}.
Example: This example omits the curly braces.
<? php
if ($ state == 1) echo "haha";
?>
Special attention here is to determine whether the equality is == instead of =, ASP programmers may often make this mistake, = is the assignment.
Example: The execution part of this example has three lines. You can not omit the curly braces.
<? php
if ($ state == 1) {
echo
echo "<br>";
}
?>
The second is to add the condition of else, except if, which can be interpreted as "what to do if something happens, or how to solve it." Grammar is as follows
if (expr) {statement1} else {statement2} Example: The above example to modify into a more complete treatment. Else because the only one line of instruction execution, so do not add braces.
<? php
if ($ state == 1) {
echo "haha";
echo "<br>";
}
else {
echo
echo "<br>";
}
?>
The third is a recursive if..else loop, usually used in a variety of decision-making. It will combine several if..else applications.
Just look at the example below
<? php
if ($ a> $ b) {
echo "a bigger than b";
} elseif ($ a == $ b) {
echo "a is equal to b";
} else {
echo "a smaller than b";
}
?>
The above example uses only two layers of if..else loop, used to compare two variables a and b. Be careful to use this recursive if..else loop, because too many layers of loops can easily lead to design logic problems, or fewer curly braces, all of which can cause program problems.
2, the for loop is only one, there is no change, its syntax is as follows
for (expr1; expr2; expr3) {statement}