PHP Full Brochure

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise operators html header php language php definition php programming php tutorial

One, PHP (PHP training PHP tutorial) installation settings

PHP can be run under a variety of operating systems, the current operating system is divided into two categories, one is the Windows series, one is the Unix family.

There are a lot of differences between installing and setting PHP in these two series operating systems, as described below.

# #2 (i) Unix-like operating system installation settings

At present, the two popular types of free Unix-like operating systems in the market, FreeBSD and Linux,linux system is more popular, but also quite a variety of types, such as Redflag,redhat system. FreeBSD has only one type, currently its release version is 3.5, here in FreeBSD as an example of the Unix-like operating system to introduce the installation of the PHP setup process, Linux and FreeBSD are similar.

1. Installation

First go to www.php.net to download the PHP installation files and http://www.apache.org download the Apache Web server. Generally put the download file into the/usr/directory.

The next step is to install the settings, and if the reader does not understand the meaning of these parameters, please do not change them.

Install Apache and PHP first.

TAR-VZXF apache_1.3.x--x represents a version number such as 12 or 13

TAR-VZXF php-4.0.x or TAR-VZXF php-3.0.x

CD apache_1.3.x

./configure--prefix=/www--/www Representative installation directory under the root directory www

Cd.. /php-4.0.x or CD. /php-3.0.x

./configure--with-mysql--with-apache=.. /apache_1.3.x--enable-track-vars

Make

Make install

Cd.. /apache_1.3.x

Php3:./configure--activate-module=src/modules/php3/libphp3.a

Php4:./configure--activate-module=src/modules/php4/libphp4.a

Make

Make install

The first to second line command uses tar to extract the downloaded compressed file files in the same name directory, and then in the Apache Extract directory environment settings, the--prefix option represents the Apache installation directory path. Then into the PHP decompression directory, PHP environment settings, if not using MySQL database, you can omit the--with-mysql option, but must join the--with-apache option, and Apache extract directory name must be correct. After you have set up PHP, compile and install to the specified directory in Apache. Then after the Apache unzip the directory to complete the PHP Schema Library installation, and then compile and install Apache after the initial installation work completed. The next thing to do is to set up Apache for the Web Server to run smoothly.

2. Settings

First set up the php.ini file,

Cd.. /php-4.0.x or CD. /php-3.0.x

PHP3:CP Php3.ini-dist/usr/local/lib/php3.ini

PHP4:CP Php.ini-dist/usr/local/lib/php.ini

Readers can edit the INI file to meet their own requirements, of course, if not clearly set, then use the default settings, the reader can also specify another directory, but need to set the conditions in the sixth step--with-config-file-path=/path then set the Apache server, You need to add the following string to the Apache settings file httpd. conf or srm.conf.

PHP 3:addtype application/x-httpd-php3. php3

PHP 4:addtype application/x-httpd-php. php

The reader can also set a different suffix name as the php file name.

# #2 (ii) installation under Windows

Download the PHP installer, ready to install, because the Windows family installation is not very different, this article takes the installation under Windows 98 as an example. You should have the PWS 4.0 installed before installation.

1. Installation

Release the compressed file to the specified directory such as C:\PHP\, and then copy the Php.ini-dist or php.ini-optimized into the C:\Windows directory (Windows NT and Windows 2000 should be C:\Winnt), and renamed to PHP.ini.

Edit your php.ini file, you can change the Extension_dir settings for your PHP installation path, as described above "c:\php", select the PHP extension you want to add, in the INI file after the extension= add Php_*.dll line , you can also load dynamically in scripts. PHP also provides additional modules that can provide additional functionality that can be downloaded from the relevant website.

2. Settings

After completing the above steps, you need to be careful to check if DCOM98 is installed, and if not, install DCOM98, which can be found in the full version of VB6. You will also need to set up the registry, which typically contains a registry file named Pws-php4.reg in the downloaded PHP compression package. You need to use Notepad to modify this file, the "[Put PATH here]" to replace the PHP extract directory, you need to be aware of the directory separation to use the double slash "\ \". Save it in the right-click menu and merge it into the registry.

3.PHP additional libraries (expansion modules)

In order to extend PHP functionality, PHP provides a number of additional libraries, which are provided in the form of DLL files, you need to modify the php.ini file before use, set the required additional libraries with extention. The following table is a common additional library, additional libraries can be downloaded to the Internet.

Php_calendar.dll Calendar Conversion

Php_crypt.dll Encryption Module

Php_dbase.dll dBASE's Function module

Php_imap4r2.dll IMAP 4 function

Php_ldap.dll LDAP functions

Php_msql1.dll MSQL 1 Customers

Php_msql2.dll MSQL 2 Customers

Php_mssql.dll MSSQL Customers

Php3_mysql.dll (built in PHP 4) MySQL function module

Php_nsmail.dll Netscape Mail function

Php_oci73.dll Oracle Function Module

Php_zlib.dll zlib Function Module

# #1 Introduction to PHP language

The use of PHP scripting language is not difficult, if there are other programming language Foundation, can be mastered quickly, even if there is no other language foundation after a little more learning can easily grasp it. PHP has a more convenient dedicated editor Phpeditor available, you can also use UltraEdit, editplus such as the editor, according to your preferences.

# #2 (i) Grammar basics

1. How to embed PHP code on a page

PHP can be embedded in the middle of the HTML code, which means that the HTML and PHP code can be mixed together, so writing code will be very comfortable. Of course, there are ways to differentiate between PHP code and HTML, and you can use the following 4 methods:

(1)

(2)

Echo ("If you want to serve XML documents in this Way");

?>

(3)

(4) <% echo ("You can also write like an ASP style"); %>

The above (1) type (4) method needs to be set separately under Windows 98 for use.

2. Notes of the program and how to conclude the sentence

In PHP, comments have the following three types of annotations:

(1)/* First line

Second line

Multi-line Comment */

(2)//single-line comment

(3) # single Comment

The above three kinds of annotations can be mixed, the reader can choose according to the habit, it is important to note that multiline comments cannot nest multiple lines of comments.

PHP statements are separated by ";", which is also a statement terminator.

3. A small example

We understand PHP's simple coding specifications and can now write a simple example of the following:

The above example is actually a standard HTML page, because PHP is interpreted to execute, so just put this file as we set up the PHP environment, you can see in the browser "Hello, this is my first PHP program."

# #2 (ii) Constants and variables

First look at one of the following examples

Example: test2_1.php

A demonstration of constants

echo "_file_"; Output: test2_1.php

echo "This is a constant"; Output: This is a constant

Define ("Theconstant", "This is a custom constant");

Echo theconstant; Output: This is a custom constant

Demo of variables

$StrOutput = "This is a variable";

Echo $StrOutput; Output: This is a variable

The echo "Variable was born like this: $StrOutput"; Output: The variable is born like this: this is a variable

echo "The problem is this: $StrOutPut"; Output: The problem is that this occurs:

?>

As can be seen from the above example, when writing PHP files, you can omit the HTML header.

1. Constants

In the above example, "_file_" is a constant, and this constant is the PHP system default, that is, the current file name for PHP, and of course there are many constants, such as "TRUE", "FALSE" and so on, if necessary, readers can go to the official PHP website query; You can also define constants yourself, just like the define ("Constant name", "Constant value") of the previous example defines a constant.

2. Variables

PHP variables are very interesting, the above example, "$StrOutput" is a variable, you can see the variable is preceded by a "$" (dollar) symbol, it is very good to distinguish between variables and programs in the other statements, while the variables in PHP can not be pre-defined and directly in the code reference, and use the The notation "$" allows our program to be more free, not only to refer to the variable as usual, but also to write directly in a string, and PHP can automatically get the value of the variable, but PHP is very strict about the case, which is clearly illustrated in the example above.

(1) The scope of the variable

Variables in PHP can be referenced directly, we define a page-level variable, and what is the relationship between the variable with the same name in the function? This is the scope of the variable, the following example:

Example test2_2.php

$strtest = "you say";

function Output1 ()

{

Echo $strtest;

}

function Output2 ()

{

Global $strtest;

Echo $strtest;

}

OUTPUT1 (); Output:

Output2 (); Output: You say

?>

As can be seen from the example above, if PHP directly refers to a variable with the same name as the page variable in the function, it will assume that the function's variable is a new variable, of course nothing, but if we add a "global" in front of it, you can get the value of the variable of the same name on the page, another way is $ globals["Strtest"];

(2) Variables of variable

The biggest difference between a variable and many common languages in PHP is the addition of a ' $ ' prefix, why take it alone? Because of this prefix, it also adds a unique way of handling PHP, where a prefix represents a common variable, but what about two prefixes? This is the variable variable, so that people may not understand, please look at the following example.

Example: test2_3.php

$name =″hello″;

$ $name =″world″; equivalent to $hello=″world″;

Echo″ $name $hello ″; Output: Hello World

Echo″ $name $ $name ″; Same output: Hello World

for ($i =1; $i <=5; $I + +)

{

${var. " $i "}= $i;

}

echo $var 3; Output: 3

?>

Everyone from the above example can basically understand the $ $name, PHP standard definition is ${$name}. It's amazing that we have variable variables to dynamically add variables.

(3) Types of variables

Readers who have learned other languages will find that PHP-defined variables do not have a defined type. In fact, the variables defined by PHP are not typed by default, and the variables are automatically determined by PHP automatically when they are used. As shown in the following example.

Example test2_4.php:

$strtype = "string";

/* Add String */

$strtype = $strtype. " Add some more strings ";

/* Another way to increase the string, and wrap the line */

$str. = "\ n the second line of string";

/* Get the first character */

$strtype = ' This is a test. ';

$first = $str [0]; Output: T

/* Get last character */

$strtype = ' This is still a test. ';

$last = $str [Strlen ($STR)-1]; Output:.

Integer type Example

$strtwo = "2.5test";

$inttype = 1;

Echo ($inttype + $strtwo)//output: 3.5

Echo ("$inttype". $strtwo)//output: 12.5test

Floating point number

$float 1 = 1.732;

$float 2 = 1.4E+2;

?>

So you can see that $strtype is actually a string variable, PHP supports five types of variables: string, Integer, floating-point numbers (Double), Array, Object.

The string is of the type. The string variable is the most commonly used type, and the two string connector is ".", as shown in the above example, PHP supports characters with special meanings after "\", such as "\ n" for carriage return.

Integer is an integral type. In a 32-bit operating system, its valid range is 2,147,483,648 to +2,147,483,647. To use the 16 binary number you can add 0x to the front.

Double is a floating-point number type. In a 32-bit operating system, its valid range is 1.7E-308 to 1.7E+308. The two types of objects and arrays are more complex, see functions and classes.

We can also use the Settype (variable, data type) function to cast the data type and use the GetType (variable) to get the variable type. This is also allowed to cast $inttype = (int) $strtype;.

# #2 (c) operator

1. Arithmetic operators

The arithmetic operation (arithmetic operators) symbol, which is the symbol used to handle arithmetic, is the simplest and most commonly used symbol, almost all of the arithmetic operators in all languages, such as ^00100010a^.

2. Logical operators

Logical operations are often used to obtain the true and false of logical values, and in all programming languages, logical operators are very important, as are the logical operators shown in ^00100010b^.

3. Relational operators

Relational operations are compared to size, as shown in ^00100010c^.

4. Bitwise operators

PHP has some of the following bits operators, such as ^00100010d^.

5. Precedence of Operators

Different operators have different order of operation in the same line program, and the order of operation in PHP is like ^00100010e^, the lower the precedence of operators, the more attention should be paid to the binding rules.

# #2 (iv) Process Control statements

One of the most basic tasks of a programmer is to tell the computer what to do next, and the Process Control statement is what makes the computer make a choice, and the Process Control statement is like a ditch in the irrigated field that guides the program to where we want to go through each fork.

1.if conditional statements

If condition statement is our most commonly used branch statement, usage also conforms to people's thinking habit, think: if If expression (Xiong ni diving got highest score) is true words statements can get gold medal else (otherwise) statements sautin take gold medal. It has three types of definitions:

(1) The first of the simplest forms.

if (expression) statement;

(2) The second form with the else (otherwise).

if (expression) {

Statement1;

} else {

Statement2;

}

(3) A third type with ElseIf.

if (expression) {

Statement1;

} elseif {

Statement2;

} else{

Statement3;

}

The IF condition statement is allowed to be nested, that is, if the statement contains additional if statements, but pay attention to the nesting level, otherwise you will not get the desired results.

2. Looping statements

Sometimes we need to do the same thing over and over again, if we are going to do it all at once, it is a very headache, and there is a special loop in the computer to do these things, of course it is a strong point of the computer.

Loop statements like a circle, from start to finish can be executed over and over, but it is best not to be round, otherwise we will fall into a dead loop. Therefore, when we use circular statements, we have to have a good entrance.

The cycle can generally be divided into the following several.

(1) While loop, also known as "when the loop", that is, "when the condition is true to execute the loop body", in PHP is defined as follows:

while (expression)

{statement}

This loop first evaluates the expression as true, and may not execute once.

(2) The Do and loop is called "Until the Loop", which executes at least once, meaning "to execute the loop body until the condition is true before exiting", PHP is defined as

do {

Statement

} while (expr);

Both of the above loops do not know the number of loops, or are used in cases where conditions are ambiguous.

(3) For loop, there are two for loops in PHP4, one for, and the other for the Foreach loop. Their main differences are:

The For loop is used for loops with known loop times;

foreach is a loop for arrays and hashes;

The PHP definition for the For loop is as follows:

for (EXPR1; expr2; expr3) {

Statement

}

The following is a simple example:

for ($i = 1; $i <=; $i + +) {

echo $i;

}

?>

PHP has arrays and hashes, followed by their concepts, the number of array elements is not fixed, if you want to access each element, with a foreach can be accessed from the first element to the last element, so that we can not find out the number of elements, we can traverse the entire array, In PHP, the Foreach loop is defined as follows:

foreach (array_expression as $value) statement//normal array

foreach (array_expression as $key = $value) statement//Hash

Please do the following example:

<? Php

foreach Example One

$a = Array (1, 2, 3, 17);

foreach ($a as $v) {

echo "Current value of\ $a: $v. \ n";

}

foreach Example Two

$a = Array (1, 2, 3, 17);

$i = 0;

foreach ($a as $v) {

echo "\ $a [$i] = $k. \ n";

}

foreach Example Three

$a = Array (

"One" = 1,

"Both" = 2,

"Three" = 3,

"Seventeen" = 17

);

foreach ($a as $k = = $v) {

echo "\ $a [$k] = $v. \ n";

}

3.SWITCH Multi-conditional statements

When we learn the IF condition statement, we notice that if the conditions are very complicated, like when we are scheduling a schedule, if the use of the IF statement will be very troublesome, and the program is not easy to read, then we recommend the use of switch statements, in fact, as long as the conditions are compound can use the switch statement, Because it helps us to make the structure clear and easier to change the conditional expression, PHP is defined as follows:

switch (expression) {

Case Condition1:

Statement1;

Break

Case Condition2:

Statement2;

Break

......

Default

Statement N;

Break

}

In this case, we introduce two special flow control statements: Break and continue.

Break is a statement that can jump out of the current loop body, while continue is going to proceed from the current execution of the continue statement to the point where the condition is judged, as in the following example:

for ($I =1; $I <=10; $I + +)

{

if ($I ==1) continue;

echo "Test:". $I;

if ($I ==2) break;

}

?>

The above program output is: Test: 2, and never execute $i=3.

4. Referencing files

In our programming process, we will certainly encounter a lot of places need many of the same modules or functions, of course, we can also use the copy and paste method to put blocks into the program, and once we want to modify one of these statements, you must modify all the pasted code, which is of course very tired, Fortunately, PHP provides a way to reference files, they are require,require-once,include,include-once. The Require method reads the file specified by require before execution, making it a part of the PHP program's Web page. The Include method for PHP is that the PHP page is read in when it encounters the file specified by the include. This way, more in line with people's habits.

We sometimes encounter this problem when we are programming, while we are trying to guarantee the independence and common nature of functions and classes, and if we call a class in a non-public file in the program, but our other processing file also calls the class in this file, then the program will make an error, that is, redefine the class, Therefore, we will have to rewrite the file or discard its independence, but there is no problem in PHP4, because PHP4 can use the Require-once and Include-once methods, as the name implies, they only call once we need the file, If there are two calls to the file, the file that is called the second time does not work.

# #2 (v) array

Through the above study, we basically have the use of PHP programming conditions, and what we learn is the basis of all programming, but if you want to go further, you need to understand the more powerful data types: arrays.

If the variable is a box that can be placed in a book, then the array is the bookshelf that can put many books, in PHP can not only put books, but also can put other items.

1. Normal array

The arrays we use in C, VB, and so on, are indexed by numbers as subscripts, as in PHP: $a [1]=1, $a [2]=2 ... $a [n], although PHP's normal array is a big step ahead of the C language in terms of data types (C can use structs instead ), and the real advantage of the C language is the introduction of a hash table (hash Table Union array).

2. Hash table (Union array)

Perhaps everyone at this time on the hash table array, still do not know, in fact, in C we used the enumerated data type, that is, we define the week's enumeration variables, we can let this enumeration contains the Monday to Sunday name, so we can directly refer to the name of the week can also get the correct value, But the enumeration needs to be predefined, the number is also defined, in order to reference, in PHP to classify it into this Union array, that is to say our subscript does not have to use numbers, so that the subscript of the array is where we can play. Take a look at the following example

Example:

$a [1]= $f; Normal array

$a ["Apple"]= "sweet"; Union array

$a [1][0]= $f; Two-dimensional arrays

$a ["Apple"][2]= "tart"; Common Arrays and Union arrays

$a ["Apple"][4]["color"][0]= "bad"; Four-dimensional array

?>

In fact, the number of dimensions of the array is best not to exceed three-dimensional, otherwise it will bring a great burden on the server, some outweigh the benefits.

# #2 (vi) function

A function is a block of statements that can perform a specific function. In these years the trend of programming language development is the reuse of code and the structure is clear, like the input and output of C is done with functions, in PHP is also the case, the function in PHP is very extensive, but also a variety of PHP functions to make PHP a powerful web programming scripting language, one of the reasons, We also encountered a lot in the previous study process, such as "echo", "require" and so on, and we can use user-defined functions to make the program structure clearer, more reasonable and more concise code. PHP has pre-defined a number of functions, the reader needs detailed information can be queried PHP Web site, and we are mainly talking about how to define the use of user-defined functions.

1. User-defined Functions

The user needs to do the same work several times when solving some problems, and there are some features such as PHP that are not solved, we advocate the use of functions. PHP defines the way the function, not as strict as the definition of the variable, where the case can be mixed, can be used in the definition of uppercase, use the lowercase function name, from this point can see PHP is very good for programmers, PHP function is defined as follows

Function name (parameter 1, parameter 2, ...)

{Statement block

return value}

A PHP function can have a return value, or it can have no return value, which can omit the return statement above.

2. Parameters

$str =″ I am the parameter 1″;

$str 2=″ I am the parameter 2″;

function TestFunc ($testarg 1,testarg2,testarg3=″ I am the test ″)

{

echo $testarg 1.″\n″;

echo $testarg 2.″\n″;

echo $testarg 3.″\n″;

$testarg 1= $testarg 1.″ test ″;

$testarg 2= $testarg 2.″ test ″;

}

TestFunc ($str, & $str 2);

echo $str. ″\n″;

echo $str 2.″\n″;

/*

After the call in the output:

I'm the parameter 1.

I'm the parameter 2.

I'm a test.

I'm the parameter 1.

I am the parameter 2 test

*/

?>

Please note that the above function, PHP parameters use more flexible, we can use the same as C inside the "" and "reference parameters, in the function to change the value of the parameter, it will directly change the value of the variable, you can also define the parameters of the default value, so that you can omit the parameters when necessary.

InstallShield 5.1 is developed by InstallShield, which provides a comprehensive set of software installation disk production technology. Installshiteld 5.1 has a new integrated development environment (IDE) compared to the previous version, allowing users to complete the installation disk only with the mouse. Installshiteld 5.1 is divided into beta, Normal and international editions, where the international version allows users to use local language text during installation. Here's how to use the Installshiteld 5.1 International edition.

# #1 One, Installshiteld 5.1 installation and uninstallation

1. Installation of system requirements such as ^00100011a^

2. Installation operation steps such as ^00100011b^

3. Uninstalling Installshiteld 5.1

After installation, the installer copies the main program files to the specified destination folder, copies the partial DLL files to the Windows system directory, and automatically creates a folder named "My Installations" in the C packing directory. As the default storage location for the installation works you have made. Before uninstalling, make a backup of the project under this directory, then open Add/Remove Programs in Windows Control Panel, select "InstallShield 5.1 Professional Edition", click "Add/Remove" to complete the uninstallation.

PHP Full Brochure

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.