PHP basic statements and functions and related Web site technology base

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Everyone may have their own servers, at least there is a space or something, but the local debugging is often not less, speed and efficiency than to get the server to play faster and more convenient, there are many PHP platform to build packages, such as xampp,wamp,appserv,easyphp, etc. I recommend myself. General development and commissioning is XAMPP

I'll give you a download address.

Http://www.phpchina.com/download/soft/amp/xampp-win32-1.6.6a-installer.exe

It's not advertising Phpchina.

This platform is very easy to use ' after installed to open the Xampp-control control program, start Apache and MySQL can play, if you want to boot automatically start these two services can be checked before the SVC registration as a service.

After the service is started, you can enter http://localhost or http://127.0.0.1 to browse in the browser, the default is XAMPP Admin page, it is recommended to make some necessary security settings according to the prompts.

MySQL database management procedures Please login http://127.0.0.1/phpmyadmin,phpmyadmin is a very powerful MySQL online management software, I believe that the use of PHP Friends of the station is not unfamiliar.

The root directory of the Web site is the Htdocs folder in the installation directory, of course, you can also change the relevant settings in the Apache/conf/httpd.conf file to specify your site root directory, change please be cautious, recommend reference to the relevant manuals.

Copy the relevant web site files to the root directory, such as DEDECMS, you can use the http://127.0.0.1/dedecms to browse the corresponding site.

Then the editor, if you want to challenge Notepad I will not stop you, just before you become a real master you will find that Notepad will make you very inefficient, we generally do not want to develop large-scale PHP projects, comprehensive consideration or recommend everyone to use the DREAMWEAVER,CS3 version is a good choice.

Below we say the base of PHP language, I believe that everyone after reading these basics, after their own site has a little trouble, or want to add a little function, should be able to do

Routine, everything from Hello world. PHP is written like this

  

echo "Hello world!";

?>

Mark description This is a PHP program, you can be abbreviated to the novice notice is that all the tags and symbols to be in the half-width state input.

The following procedure must be entered inside, I will be abbreviated.

ECHO is the output statement, and all strings followed by ECHO are output as HTML sent to the client's browser

So if you write this

echo "Hello world!";

Will output a bold hello world! instead of the whole Hello world!.

After each PHP statement you need to add; At the end, remember, this is where beginners often forget.

"" is a string, simple to understand is a string of characters, here is to mention the variable, PHP, the variable is not required to declare, only in the use of the variable name before adding $ can be, look at an example.

$str = "Hello world!";

Echo $str;

This paragraph still prints Hello world!

That's a bit of a program based station friend may ask, then how to determine the data type?

Here I want to explain that PHP data can be roughly divided into 8 types:

String: Strings

Integer: Integers

float: Floating-point number (decimal)

Boolean: Boolean

Array: Arrays

Object: Objects

There are two other kinds of special

Null: null value

Resource: Resource type

But in the use of variables, you have to do is to add $ on it, PHP will automatically help you to complete the corresponding data recognition and conversion, the specific conversion rules interested in the station friends can go to consult the relevant tutorials.

For example:

$STR = "123";

$num = 456;

Echo $str. $num. 789 ";

The variable $str here is String, $num is an integer, after the. Operation (that is, the connection string operation) will output 123456789

But we $str the last echo $num. 789 ", change to echo $str + $num +" 789 ", then output 1368, we appreciate the PHP in the two operations of the automatic conversion of data.

Of course, we also have a method of coercion or manual conversion, (string) $num represent the conversion of an integer $num to a string

It is worth noting that (string) $num the whole is string, but $num is still an integer, which does not change

We can also use the GetType () function to track the type of a variable at any time. For example, the last addition to the Echo GetType ($STR);

For examples of constants defined by PHP, see:

Define ("USERNAME", "ERROR.") SYS ");

Define ("QQ", "110187");

Echo USERNAME. Q is ". QQ;

This section will output the ERROR. The Q of SYS is 110187, the use of constants is simple, and I don't explain too much.

The following is followed by the PHP operator, which is similar to other languages in the C language, and has a C-language base that can skip '

In addition to the above mentioned. and + operators, the other operators of PHP are as follows

Arithmetic operators: + Plus, minus, * multiply,/divide,% to take remainder, + + variable self-add,--variable self-minus

For example:

$a = 1;

$b = 2;

echo $a + $b; 3

echo $a-$b; -1

Echo $a * $b; 2

echo $b/$a; 2

echo $b% $a; 0

echo $a + +; 1

echo $a; 2

echo + + $a; 3

echo $a-; 3

echo $a; 2

echo-$a; 1

is the annotation, which is written to the programmer, the program itself ignores all comments in the statement, the large section of comments can be used/* Comment content/*, the previous program in each sentence of the operation results in the comments, no program based station friends please combine examples of special careful experience of + + operations and--operations.

Assignment operator: =,+=,-+,*=,/=,%=,/=

$a = 3;

$a +=1;

echo $a; 4

$a +=1 is shorthand for $a= $a +1, and so on for other assignment operators.

Logical operator:> is greater than,<, >= is greater than equal, <= is less than equal, = = equals, = = value and type are equal,!= is not equal to,&& or and, and, Or OR OR, XOR exclusive OR,! Non

It is worth novice attention is to determine whether two variables are equal to use = =, such as $a== $b, and $a= $b, not to determine whether the two are equal, but bits value to $a.

Bitwise operators:& bitwise with, | Bitwise OR, ^ xor or,<< left,>> move right, ~ bitwise counter

Other operators:& the method or property of the address,-> object,=> array operations,?:

?: It is important to explain, for example

$a = 1;

$b = 2;

echo $a < $b 3:4;

This output is 3, because the left side of the judge $a is less than bits, the answer is yes, so output 3, otherwise output 4.

Here's the statement.

If statement, if is the most commonly used program logic, many times we have to change a small function is to change the if logic can be done

For example

$a = 1;

$b = 2;

if ($a > $b) {

echo "A is greater than B";

}else{

echo "A is less than B";

}

If it is if else is otherwise

It means

First assign the 1 to the variable $a and then assign 2 to the variable bits, if the $a> $b output A is greater than B, otherwise the output A is less than B, the careful friend can find that the logic is similar to the above: the operation is very much the same.: It is a shorthand form of if, often used?: can improve writing efficiency

Switch statement, which is also a conditional selection statement, relative to if, it is a multiple selection statement, that is, multiple criteria can be judged at one time

For example

$num = 1;

Switch ($num) {

Case 1:

The value of echo "num is 1";

Case 2

The value of echo "num is 2";

Case 3

The value of echo "num is 3";

Default:

echo "Num has no value";

}

Correct

$num = 1;

Switch ($num) {

Case 1:

The value of echo "num is 1";

Case 2:

The value of echo "num is 2";

Case 3:

The value of echo "num is 3";

Default:

echo "Num has no value";

}

The above case 2 and case 3 behind no: number, PHP program must pay attention to the format, otherwise it will be an error, many of the site's small errors are caused by

The meaning of this paragraph is very simple

First, the $num assignment 1,switch statement to determine the value of $num, if it is 1 output num value is 1,2 and 3 The case also, default is the defaults, if $num 1,2,3 are not when the output num no value

While statement, the same as the conditional structure of if, another important program structure is the loop structure, while is a circular statement

For example

$a = 1;

while ($a <5) {

echo "hi!";

$a + +;

}

This section will continuously output hi!hi!hi!hi!

It means assigning 1 to $a.

Then into the while loop while the meaning, meaning that when the $a is less than 5 when the output hi! and then $a to do their own operation, that is, each cycle $a on a freshman, when the $a equals 5 will not perform output hi! "" so will output 4 times hi!

Do While statement

For example

$a = 1;

do{

echo "hi!";

}while ($a >1)

The difference between the output hi!,do while and the while is that the while checks to see if the condition is satisfied before deciding whether to go into the loop, and does while is going into the loop regardless of whether the condition is met, and then using the while to check if the condition is met to determine whether to continue the loop ' So this paragraph although $a is only 1, not greater than 1, but still output a hi!

For statement, for same as if is the most used statement, also is a loop, it can completely replace while and do while

For example, we rewrite the example above while

$a = 1;

For ($i =1 $i <5; $i + +) {

echo "hi!";

}

This will get the same output as in the while example

Where $a is assigned a value of 1

Start for loop

Assign a value of 1 to the loop variable I, this is also the initial value of the loop, $i <5 is the condition of each cycle to check, only to meet this condition will execute the statement in the loop body, $i + + is a loop in the body of the statement to do after each, here is the loop variable I for self operation, The principle is the same as while, each cycle I will increase by 1 so when I equals 5 o'clock, it is not executing the loop ' last output 4 times hi!

Break and re-enters statements

Break statements are used for interrupts, as in the switch statement above, there are breaks behind each case, which means that each time the output is terminated, the execution of the switch statement is aborted.

$num = 1;

Switch ($num) {

Case 1:

The value of echo "num is 1";

Case 2

The value of echo "num is 2";

Case 3

The value of echo "num is 3";

Default:

echo "Num has no value";

}

No break.

$num = 1;

Switch ($num) {

Case 1:

The value of echo "num is 1";

Case 2

The value of echo "num is 2";

Case 3

The value of echo "num is 3";

Default:

echo "Num has no value";

}

Can not perform the original function

The re-enters statement is paused

$a = 1;

For ($i =1 $i <5; $i + +) {

if ($i ==3) re-enters;

echo "hi!";

}

This section will only output 3 times hi!, because when I equals 3 o'clock, the loop is paused once

Well, the front is based on the PHP language, with these, you can write a complete block of code, we have time to continue to talk about some of the other basic PHP content, including functions, strings, arrays, regular expressions, PHP5 object-oriented Technology, PHP database programming, as well as file systems and so on content

There was no preparation, not very well spoken, today I said so many "' I guess I can hear a little bit of" "but it's okay." PHP is generally a more easy to learn the function and extensibility are good language ' and so on to post to the forum ' interested friends can see a bit more I hope we can help you with your station.

There's not a lot of basic stuff. ' I hope everyone sees it ' and can change some of the bugs and functions of the site.

There is a C based on the ' easy to understand ' the contents of the previous half is C things ' hehe '

' Programming is a lot of practice ' do not ask yourself to write ' do webmaster ' Basic code or can read for good ' all do not beg ' and not be fooled by technical staff

Related Article

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.