PHP Complete Manual_PHP Tutorial

WBOY
Release: 2016-07-13 17:23:54
Original
1017 people have browsed it

1. PHP installation settings PHP can run under a variety of operating systems. Current operating systems are mainly divided into two categories, one is the Windows series and the other is the UNIX series. There are big differences in the installation and setting of PHP's operating environment in these two series of operating systems, which are described below. ##2 (1) Installation settings under UNIX-like operating systems Currently, there are two popular free UNIX-like operating systems on the market, FreeBSD and Linux. Linux systems are more popular and there are many types, such as RedFlag, RedHat and other systems. There is only one type of FreeBSD, and its current Release version is 3.5. Here, FreeBSD is used as an example to introduce the PHP installation and setup process under a UNIX-like operating system. Linux and FreeBSD are similar. 1. Installation First go to www.php.net to download the PHP installation file and http://www.apache.org to download the Apache WEB server. Generally, the downloaded files are placed in the /usr/ directory. Next, the installation settings begin. If readers do not understand the meaning of these parameters, please do not change them at will. Install Apache and PHP first. tar -vzxf apache_1.3.x --x represents the version number such as 12 or 13, etc. tar -vzxf php-4.0.x or tar -vzxf php-3.0.x cd apache_1.3.x ./configure --prefix=/ www --/www represents the 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 and second lines of the command use tar to decompress the downloaded compressed file and restore it to the directory of the same name, and then set the environment in the Apache decompression directory, - The -prefix option represents the installation directory path of Apache. Then enter the PHP decompression directory and set the PHP environment. If you are not using a MySQL database, you can omit the --with-mysql option, but you must add the --with-apache option, and the Apache decompression directory name must be correct. After setting up PHP, compile and install it into the specified directory of Apache. Then complete the installation of the PHP pattern library in the Apache decompression directory, compile and install Apache, and the installation work is initially completed. The next step is to configure Apache so that the Web Server can run smoothly. 2. Set up the php.ini file first, 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 the settings are not clear, the default settings will be used. Readers can also specify another directory, but they need to be specified in Chapter 1. Six steps to set conditions--with-config-file-path=/path. Then set the Apache server. You need to add the following string to the Apache configuration file httpd.conf or srm.conf. PHP 3: AddType application/x-httpd-php3 .php3 PHP 4: AddType application/x-httpd-php .php Readers can also set another suffix name as the file name of php. ##2 (2) Installation under Windows Download the PHP installation program and prepare for installation. Because the installation of the Windows series is not very different, this article takes the installation under Windows 98 as an example. You should have PWS 4.0 installed before installation. 1. Install and release the compressed file to the specified directory such as C:\PHP\, and then copy php.ini-dist or php.ini-optimized to the c:\windows directory (it should be c:\winnt in Windows NT and Windows 2000) ) and renamed to php.ini. Edit your php.ini file, you can change the extension_dir setting to the installation path of your php, such as "c:\php" mentioned above, select the php extension module you want to install, in the ini file Add the php_*.dll line after extension=, you can also load it dynamically in a script. PHP also provides some additional modules that can provide other functions, which can be downloaded from relevant websites. 2. Settings After completing the above steps, you need to check whether DCOM98 is installed. If not, you also need to install DCOM98, which can be found in the full version of VB6. You also need to set up the registry. Generally, the downloaded PHP compressed package contains a registry file named PWS-php4.reg. You need to modify this file with Notepad first, and replace "[PUT PATH HERE]" with the PHP decompression directory. Please note that directories must be separated by double slashes "\\".After saving, just merge it into the registry in the right-click menu. 3. PHP additional libraries (extension modules) In order to extend the functions of PHP, PHP provides many additional libraries. These additional libraries are provided in the form of DLL files. Before use, you need to modify the php.ini file and use Extention to set the required additional libraries. The following table shows commonly used add-on libraries. More add-on libraries can be downloaded from the Internet. Php_calendar.dll Calendar conversion php_crypt.dll Encryption module php_dbase.dll Dbase function module php_imap4r2.dll IMAP 4 function php_ldap.dll LDAP function php_msql1.dll mSQL 1 client php_msql2.dll mSQL 2 client php_mssql.dll MSSQL client php3_mysql.dll (PHP 4 built-in) MySQL function module php_nsmail.dll Netscape mail function php_oci73.dll Oracle function module php_zlib.dll ZLib function module ##1 2. Getting started with PHP language Using PHP scripting language is not difficult, if you have a foundation in other programming languages , can be mastered quickly, even if there is no other language foundation, you can easily master it after a little more study. PHP has a more convenient special editor PHPEditor available for use. You can also use editors such as UltraEdit and Editplus, depending on your preference. ##2 (1) Grammar basics 1. How to embed PHP code in the page PHP can be embedded in the middle of the HTML code, which means that HTML and PHP codes can be mixed together, so writing code will be very comfortable. Of course, there must be a way to distinguish PHP code from HTML. You can use the following four methods: (1) echo (“这是最常用的方式”); ?> (2) (3) (4) (4) above This method requires separate settings to be used under Windows 98. 2. Program comments and how to end statements. In PHP programs, comments have the following three comment methods: (1)/* First line, second line, multi-line comment*/ (2)// Single-line comment (3)# Single line Comments The above three types of comments can be mixed, and readers can choose according to their habits. It should be noted that multi-line comments cannot be nested in multi-line comments. PHP statements are separated by ";", which is also the statement terminator. 3. Small example We have learned about the simple coding standards of PHP. Now we can write a simple example as follows:

The first PHP program The above example is actually a standard HTML page. Because PHP is interpreted and executed, you only need to put this file in the PHP environment we have set up, and you can see it on the browser. "Hello, this is my first PHP program".##2 (2) Constants and variables First, look at the following example. Example: test2_1.php As can be seen from the above example, the HTML header can be omitted when writing PHP files. 1. Constant "_FILE_" in the above example is a constant, and this constant is defaulted by the PHP system, which represents the current file name of PHP. Of course, there are many constants, such as "TRUE", "FALSE", etc., if the reader needs If so, you can go to PHP's official website to check; if you feel that the constants are not enough, you can also define the constants yourself, just like define ("constant name", "constant value") in the above example to define constants. 2. Variables PHP variables are very interesting. In the above example, "$StrOutput" is a variable. You can see that there is a "$" (dollar) symbol in front of the variable, so it is very easy to distinguish the variable from other statements in the program. At the same time, variables in PHP can be referenced directly in the code without being predefined, and the use of symbols such as "$" can give our program greater freedom. Not only can variables be referenced as usual, but also in Write directly in a string, and PHP can automatically obtain the value of the variable, but PHP is very strict about case distinction, which is clearly illustrated in the above example. (1) Scope of variables Variables in PHP can be directly referenced. We have defined a page-level variable. What is the relationship between it and the variable of the same name in the function? This is the problem of the scope of variables, as shown in the following example: Example test2_2.php As can be seen from the above example, if PHP directly references a variable with the same name as a page variable in a function, it will consider the variable of the function to be a new variable. , of course nothing is output, but if we add "global" in front of it, we can get the value of the variable with the same name on the page. Another similar method is $GLOBALS["strtest"]; (2) Variable The biggest difference between variables in PHP and many commonly used languages is the addition of a '$' prefix. Why talk about it separately? Because of this prefix, PHP also adds a unique processing method. One prefix represents an ordinary variable, but what about two prefixes? This is a variable of variables. You may not understand this. Please see the following example. Example: test2_3.php $name=″hello″; $$name=″world″; //等同于$hello=″world″; echo ″$name $hello″; //输出:hello world echo ″$name $$name″; //同样输出:hello world for($i=1;$i From the above example, you can basically understand $$name. The standard definition of PHP is ${$name}. Once we have variables of variables, we can dynamically add variables, which is simply magical. (3) Type of variable Readers who have studied other languages will find that the variables defined by PHP do not have a defined type? In fact, variables defined by PHP have no type by default, and PHP automatically determines the type of the variable when it is used. Just like the following example demonstrates. Example test2_4.php: php $strtype="字符串"; /*添加字符串*/ $strtype=$strtype."再增加一些字符串 "; /* 另一种增加字符串方式,并换行*/ $str .= "\n第二行的字符串"; /* 得到第一个字符*/ $strtype=This is a test.; $first = $str[0]; //输出:T /*得到最后一个字符*/ $strtype=This is still a test.; $last=$str[strlen($str)-1]; //输出:. //整数类型例子 $strtwo="2.5test"; $inttype=1; echo ($inttype+$strtwo) //输出:3.5 echo ("$inttype".$strtwo) //输出:12.5test //浮点数

www.bkjia.com true http: //www.bkjia.com/PHPjc/532192.html TechArticle 1. PHP installation and settings PHP can run under a variety of operating systems. Current operating systems are mainly divided into two categories , one is the Windows series, and the other is the UNIX series. In these two series of operating systems...
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!