Administrators in more than 3 million Internet sites worldwide are using PHP, making it the most popular server-side scripting language. It is characterized by fast running speed, stable and reliable, cross-platform, and is open source software. Unlike the level you use, PHP can be very simple, can also be complicated, you can use it to send HTML table elements, you can also integrate Java and XML in the PHP application.
If you have a certain understanding of PHP or have seen some preliminary textbooks, these techniques can expand your understanding of PHP and make you master some common and advanced PHP functions.
First, install PHP to apache's DSO
PHP is often used with Apache on the Linux / UNIX platform. When installing PHP, there are three installation methods to choose from: static mode, dynamic mode (DSO), CGI binary mode.
Because it is easy to maintain and upgrade, I strongly recommend installing PHP in DSO. For example, if the installed PHP only supports the database, then you want to install the encrypted module, just run "make clean", add a new configuration option, then run "make" and "make install", one The new PHP module will be installed in the appropriate location in Apache, then restart Apache without recompiling Apache.
The following steps will install a brand new Apache and install php in DSO:
1. Get the latest version of Apache source code from the Apache Software Foundation;
2, put the resulting source code in / usr / local / or / opt / directory, or in any of your specified directory;
3. Running Gunzip to decompress the file to get the file that suffix .tar;
4. Run the following command to install the file to the Apache_ [Version] directory:
Tar-xvf apache_ [version] .tar
5. Go to the / usr / local / apache_ [version] directory (or the directory of the compressed file in step 4);
6. Type the following command to prepare to compile Apache, replace [PATH] with your own path, for example, / usr / local / apache [version], now set up mod_so's new value, it will allow Apache to use DSO module;
7. When you return to the prompt state, type Make and wait back to the prompt status again;
8. Execute the "make install" command.
At this point, Apache has been installed and the system will return to the prompt state. Let's start installing PHP:
1. Find the latest version of the link in the download area of the PHP home page;
2. Download the file to an appropriate directory, such as / usr / local / or / opt / or any directory you specify;
3. Running Gunzip to decompress the file to get the file that suffix .tar;
4. Execute the following command to install the file in the PHP- [Version] directory:
TAR-XVF PHP- [Version]
5, enter the / usr / local / php- [version] directory or the directory specified in step 4;
At this point, it has been prepared to install PHP in DSO, and the only configuration option that needs to be modified is with-apxs (this is a file in the bin directory of Apache). In order to get a high performance, I didn't install the support module for MySQL.
./configure --with-mysql = / [path to mysql] --with-apxs = / [path to apxs]
6. If you return to the prompt state, execute the make command, wait for the re-return to the prompt state; 7, execute the make install command.
At this point, the system is installed in the DSO mode in the Apache's module directory and returns to the prompt state after proper modification of Apache's httpd.conf file. After returning to the prompt state, you also need to modify the apache's httpd.conf file.
1. Find a line containing ServerAdmin, add your email address, as shown below:
ServerAdmin you@yourdomain.com
2. Find the line starting with ServerName and change it to a true value, for example:
ServerName Localhost
3. Find the section as shown below:
# And for php 4.x, use:
#
#Addtype application / x-httpd-php .php
#Addtype application / x-httpd-php-source .phps
Modify the contents of these rows, making the addtype of PHP 4.0 no longer a comment, and add the file suffix name that I want to use in PHP, the above content becomes as follows:
# And for php 4.x, use:
#
AddType Application / X-httpd-php .php .phtml
AddType Application / X-httpd-php-source .phps
Save the file, return to the previous directory, perform the following command to restart Apache:
./bin/apachectl start
If there is no error message when starting, you can test the installed Apache, PHP by creating a file named PHPINFO.PHP:
phpinfo ()?>
Save this file to the Apache 's Document Root (HTDOCS), then turn on the browser, type http: //localhost/phpinfo.php address, and there will be a lot of variables and their values.
If you want to reconfigure the PHP, you need to run the make clean command again, then perform the ./configure command with a series of options, then execute the make and make install commands, a new module appears in the Apache directory module, just re-re- Start Apache loading this new module, everything is OK.
Second, use the PHP itself dialogue
The most expectation of PHP 4.0 should be support for dialogue. Users of PHP 3.0 must use third-party software. Otherwise, they cannot use dialogue, and do not support dialogging has always been one of PHP's largest shortcomings.
As long as users are browsing your website, you can use dialogue maintenance with variables related to a specific user without having to create multiple cookies, using hidden table fields or store information in the database.
Start a conversation on a web page, you will know that the PHP engine knows that you want to start a conversation (if you have not started) or continue the current conversation:
session_start ();
Starting a dialog will send a identifier string to the user (for example, 940f8B05A 40D5119C030C9C9C7745AEAD9), at the server side, created a temporary file that matches the identifier string, such as SESS_940F8B05A40D5119C030C9C7745AEAD9, which contains registered dialog variables and their values.
The most common example used to display the role of the conversation is to access the counter. Start the PHP module, make sure the PHP code is the first line of the file, do not have spaces, HTML code, and other code before the PHP code. Because the conversation will send a head, if there is space and HTML code before session_start (), an error message will be obtained.
// If there is still no user who targets a user, start a conversation:
session_start ();
Then sign up for a variable name for count:
Session_register (count);
After registering a dialog variable, as long as the conversation exists, the variable of the name is COUNT also exists. Now, the count variable has not been assigned. If you perform an additional action to it, its value changes to 1.
$ count ;
Comprehensively synthesize the above content, if you haven't started a conversation, you will start a conversation; if there is no dialogue ID, you specify a good time, register a variable of $ count, do adding $ count 1 Operation indicates that the user has accessed the page for the first time.
To know the number of times the user accesses this page in the current dialog, as long as the value of $ count variable:
Echo "
youve been here count Times. p>";
All access counter code as follows:
session_start ();
Session_register (count);
$ count ;
Echo "
youve been here count Times. p>";
?>
If the above script file is reloaded, it will find that the value of the variable count has increased by 1, cool.
You can also register a array variable in the dialogue, assume that we registered a variable name $ FAVES:
$ FAVES = Array (Chocolate, Coffee, Beer, Linux);
You can register an array variable like a simple variable:
Session_register (failes);
Quote the array variables and reference simple variables have no differential. If a user points out the hobby in the webpage, you can register his hobbies into a group variable called $ FAVES, and then you can be on another web page. It is convenient to display these hobbies:
session_start ();
echo "My User Likes:
While (List (, $ V) = Each ($ FAVES)) {
Echo "
ECHO " ul>";
?>
Then you get a list about the user's hobbies.
The dialog variable cannot be covered by the string, that is, we can't enter http://www.yourdomain.com/yourscript.php? Count = 56 Specify a new value to the registration variable $ count, this is important for security: You can only delete a registered dialog variable in the script of the server.
If you want to completely delete a dialog variable, first you need to log out from the system:
Session_unregister (count);
The script to completely delete a dialog variable is very simple, as shown below:
session_destroy ();
Using dialog variables can reduce the frequency of accessing the database, making the code clearer, and can reduce the number of cookies sent by the user, which is the easiest way.
Third, the document is our friend, regardless of the size of the website you develop, you should realize the importance of code reuse, whether these code is HTML, or PHP code. For example, you must change a footer that contains copyright information at least every year. If your website contains 1000 pages, it is also an annoying thing to modify each year.
In PHP, at least there are at least a few functions can help you implement the purpose of the code reuse, the function used depend on the code you reuse, the main functions are:
* incrude () and include_once ()
* Require () and repeire_once ()
The incrude () function contains and calculates a given file, for example:
INCLUDE (/ home / me / myfile);
Any code in the include file is executed within the code range of include (), you can use include () and fopen () in your own server, contain the target file on another server.
The functionality of include_once () is the same as include (). The difference between the two is whether it checks if the code in a file is already included in an existing script. If the code already exists, it will not be included again.
Require () function replaces itself with the content of a given file itself, this replacement process occurs during the PHP engine compile code, not during execution, it is not like include () will be calculated first. The Require () function is more used in static elements, and include () is more used in dynamic elements. Similar to include_once (), request_once () will first check if the given code is inserted, and if the code already exists, it is no longer inserted.
In order to understand its content, in the elements of copyright information, static text, and other elements that do not contain variables or elements that rely on other ongoing scripts, I tend to use the Require function. E.g:
[a Lot of Content]
// INSERT COPYRIGHT
Require (/ home / me / mycopyright);
?>
Body>
Html>
On the other hand, I often use include () to control many functions in the beginning of the file:
// Get a library
INCLUDE (/ home / me / myfunctions);
// Do PHP Things with my functions?>
[a Lot of Content]
Body>
Html>
The next question is "Where is the include and the require file?", A simple answer to this problem is "" If you include a database connection with the username and password, you are sure They will not be placed in the document root directory to all people.
Included or Required files can be available anywhere on the system, as long as the user on the system running in PHP can access these files, you can make these files any suffix, or do not use the suffix.
Use include () and Require () to make a generalization of elements in the website, and bring you great convenience when you need to upgrade your website.
Fourth, the maintenance of PHP and file system
There are many functions related to the file system in PHP. These functions can not only open files, but also display content, mobile files, and other functions in the directory, and many people have even developed the Internet-based file resource manager with PHP. About the interpretation of the filepread: In Windows, you can use / and / symbols in the path, while only / symbols can be used in other operating systems. For consistency, we use / symbols.
The following script sample can display a list of directory, the comment is already included in the code:
/ * Stores the full path name of the directory you want to read into a variable of $ dir_name. * /
$ DIR_NAME = "/ home / me /";
/ * Create a handle that is the result of opening a given directory * /
$ dir = OpenDir ($ DIR_NAME);
/ * Create a text block to place list elements (file name) * /
$ FILE_LIST = "
/ * Using a While statement, read all the elements in the open directory, if the name of the file is not "." Or "..", the name in the list * /
While ($ file_name = readdir ($ dir)) {
IF (($ file_name! = ") && ($ file_name! =". ")) {
$ FILE_LIST. = "
}
}
$ FILE_LIST. = " ul>";
/ * Close the open directory, end the PHP module * /
CloseDir ($ DIR);
?>
HEAD>
files in: Echo "$ dir_name";?> P>
echo "$ file_list";?>
Body>
Html>
Ok, we have got a list of directories. It should be noted that the contents of the system on the system that should be read by reading a file (later we will explain later), the user on the system of PHP must have at least read files.
Here is an example of how to copy files:
/ * Assign the full path of the original file you want to copy to a variable of the name $ Original, give a full path to the copy file to a variable of $ Copied * /
$ othern = "/ home / me / mydatabaseDump";
$ COPIED = "/ Archive / mydatabaseDumo_1010";
/ * Use a copy () function to copy the original file, if the copy is not completed, an error message is displayed * /
@Copy ($ Original, $ Copied) or Die ("COULDNT COPY FILE.");
?>
This example is the prototype of a file backup system. When this script is run, it copies the file to a different location for saving. Slightly modify the daemon, you can execute it at the time you specified during the day without the need for user intervention. Assume that you install Lynx on the system, you can create a daemon entry to access this file, access this file, run this script and create a copy file, the following example will run this script at 5 o'clock in the morning, then close Lynx:
0 5 * * * [username] lynx -dump http://localhost/copyfile.php 1> / dev / null 2> & 1
If you run a CGI version of PHP, you can skip the Lynx section, and call the binary directly:
0 5 * * * [username] php /Path/to/copyfile.php 1> / dev / null 2> & 1
Five, rich array functions
Add 30 functions related to the number of groups in PHP 4.0, some common functions can determine if an array contains an element, counts elements in an array, add or delete elements in an array or alignment groups The elements in the middle are sorted.
If there is a big array, you need to find out if you contain a specific element, you can use IN_ARRAY (). The following example will display "Not Found In this Array", because in an array of $ Nameserray, you don't have such an element in the $ NameserRay array.
$ Nameserray = Array ("Joe", "Jane", "Bob", "Mary", "Paul", "EDDIE", "John");
$ lookingFOR = "albert";
IF (In_Array ($ LOOKINGFOR, $ NameserRay) {
Echo "Youve Found IT!";
} else {
Echo "NOT Found in this Array!";
}
?>
If you change the value of $ lookingfor to Mary, you will get information about "Youve Found IT!" Because Mary is an element in the NameserRay array.
If you want to count the number of elements in an array, just simply use the count () function:
$ Nameserray = Array ("Joe", "Jane", "Bob", "Mary", "Paul", "EDDIE", "John");
$ count = count ($ nameserray);?>>
The value returned $ count is 7.
You can add an element at the beginning or end of an array, and use array_merge () to create a new array of elements in two or more groups, when combined, the order of the elements is arranged in the specified order, if the original The array is sorted by sequence, and it needs to be reordered it after the merger.
We can first add an element with array_push () at the end of the array:
/ * Establish an array * /
$ fruitArray = array ("Apple", "Orange", "Banana", "Kiwi", "PEAR");
/ * Add an element to an array * /
Array_push ($ FRUITARRAY, "GRAPE", "PineApple", "Tomato"); / * Shows each element and its serial number * /
While (List ($ key, $ value) = Each ($ fruitaRray) {
Echo "$ Key: $ Value
";
}
?>
Run the above program will get the following results:
0: apple
1: Orange
2: Banana
3: Kiwi
4: Pear
5: grape
6: PineApple
7: Tomato
If you need to add an element at the beginning of the array, the code is similar to the above code, and the only difference is to replace Array_UNSH () in place_push ().
/ * Establish an array * /
$ fruitArray = array ("Apple", "Orange", "Banana", "Kiwi", "PEAR");
/ * Add an element to an array * /
Array_unshift ($ FRUITARRAY, "Grape", "PineApple", "Tomato");
/ * Show each element and its serial number * /
While (List ($ key, $ value) = Each ($ fruitaRray) {
Echo "$ Key: $ Value
";
}
?>
Run the above program will get the following results:
0: grape
1: PineApple
2: Tomato
3: apple
4: Orange
5: Banana
6: Kiwi
7: Pear
Array_merge () function can combine two or more arrays into an array.
/ * Establish the first array * /
$ fruitArray = array ("Apple", "Orange", "Banana", "Kiwi", "PEAR");
/ * / Establish a second array * /
$ VEGARRAY = Array ("Carrot", "Green Beans", "Asparagus", "Artichoke", "Corn");
/ * Combination of these two numbers and a array * /
$ GoodFoodArray = Array_Merge ($ FRUITARRAY, $ VEGARRAY);
/ * Show each element and its serial number * /
While (list ($ key, $ value) = Each ($ GoodFoodArray) {
Echo "$ Key: $ Value
";
}
?>
Run the above script will get the following result:
0: apple
1: Orange
2: Banana
3: Kiwi
4: Pear
5: Carrot
6: Green Beans
7: Asparagus
8: Artichoke
9: Corn
Now we have mastered how to add an element and merge array, let's take a look at how to delete an element from an array. Delete an element from an array can use the Array_POP () function, using the array_shift () function to delete an element from an array. Although an element is removed from array_pop () or array_shift (), you can use this element as a variable.
Use array_pop () to delete an element from the end of an array:
/ * Establish an array * /
$ fruitArray = array ("Apple", "Orange", "Banana", "Kiwi", "PEAR");
/ * Delete an element from the end of the array * /
$ popped = array_pop ($ fruitarray);
/ * Show the contents of the deleted number of groups and your deleted elements * /
While (List ($ key, $ value) = Each ($ fruitaRray) {
Echo "$ Key: $ Value
";
}
echo "
And Finally, in $ Popped: $ POPPED";
?>
Run the above script get the following results:
0: apple
1: Orange
2: Banana
3: Kiwi
And finally, in $ Popped: PEAR
Let's discuss an example of deleting an element from an array:
/ * Establish an array * /
$ fruitArray = array ("Apple", "Orange", "Banana", "Kiwi", "PEAR");
/ * Delete an element from one array * /
$ shifted = array_shift ($ fruitaRray);
/ * Show the contents of the deleted number of groups and your deleted elements * /
While (List ($ key, $ value) = Each ($ fruitaRray) {
Echo "$ Key: $ Value
";
}
echo "
And Finally, IN $ Shifted: $ Shifted";
?>
Run the above script will get the following display result:
0: Orange
1: Banana
2: Kiwi
3: Pear
And Finally, In $ Shifted: Apple
There are also several functions to sort elements in arrays, but we will only briefly introduce basic sort functions, explaining the process of sorting:
/ * Establish an array * /
$ fruitArray = array ("Apple", "Orange", "Banana", "Kiwi", "PEAR");
/ * Sort array * /
Sort ($ fruitaray);
/ * Show each element and its serial number * /
While (List ($ key, $ value) = Each ($ fruitaRray) {
Echo "$ Key: $ Value
";
}
?>
Run the above script gets the following display results:
0: apple
1: Banana
2: Kiwi
3: Orange
4: Pear
6. Creation of moving images
Just install some third-party library files and have certain geometries, you can use PHP to create and process images. In fact, this doesn't need too much geometries, because our university does not graduate, still can use PHP to create images.
You need to install the GD library file before using the basic image creation function. If you want to create a function related to JPEG, you will need to install JPEG-6B. If you want to use the Type 1 type font in the image, you must install T1LIB.
Before establishing an image creation environment, you need some preparations. First, install T1LIB; secondly install JPEG-6B, then install the GD library file. Be sure to install in the order here, because JPEG-6B is used when compiling GDs is used, and if JPEG-6B is installed, it will be wrong when compiling. After installing these three components, you also need to reconfigure PHP, which is one of you who is featured by using DSO way to install PHP. Run Make Clean, then add the following content in the current configuration:
--with-gd = [/ patH / to / gd]
--with-jpeg-dir = [/ path / to / jpeg-6b]
--with-t1lib = [/ patH / to / t1lib]
After completing the addition, execute the make command, then execute the make install command. After restarting apache, run PHPINFO () to check if the new settings have taken effect. You can start the image creation work now.
Depending on the version of the installed GD library file, you may or cannot create a graphic file in GIF or PNG format. If you install GD-1.6 or previous version, you can use the GIF format file but cannot create a PNG format, if Installing the version after GD-1.6, you can create a PNG file but cannot create a file in GIF format.
Creating a simple image also requires many functions, we will explain step by step.
In this example, we will create an image file in a PNG format. The following code is a header of the MIME type of image created:
Header ("Content-Type: Image / PNG");
Create a variable representing a blank image using ImageCreate (), which requires parameters of image size in pixels, which is imagecreate (x_size, y_size). If you want to create an image of 250x250, you can use the following statement:
$ newimg = imagecreate (250, 250);
Since the image is still blank, you may want to use some colors to fill it. However, you need to first use the ImageColoralLocate () function to specify a name with its RGB value for this color, the format of this function is imagecolorallocate ([Image], [Red], [Green], [Blue]). If you want to define the sky, you can use the following statement:
$ skyblue = imagecolorallocate ($ NEWIMG, 136, 193, 255);
Next, you need to use the imagefill () function to populate this image with this color, and the imagefill () function has several versions, such as ImageFillRectangle (), ImageFillPolygon (), and so on. For simplicity, we use imagefill () functions through the following format:
Imagefill ([Image], [Start X Point], [Start Y Point], [Color])
Imagefill ($ NEWIMG, 0, 0, $ SKYBLUE);
Finally, the image handle and the memory occupied after the image is established:
ImagePNG ($ newimg);
ImageDestroy ($ newimg);?>
In this way, all code to create images are as follows:
Header ("Content-Type: Image / PNG");
$ newimg = imagecreate (250, 250);
$ SkyBlue = ImageColoralLocate ($ NEWIMG, 136, 193, 255); ImageFill ($ NewImg, 0,0, $ SkyBlue);
ImagePNG ($ newimg);
ImageDestroy; $ newimg;
?>
If this script file is saved as SkyBlue.php, you will see an image of a blue 250x250 PNG format with a browser.
We can also use image creation functions to process images, such as making a large image into a small image:
Suppose you have an image, you want to cut out a 35x35 size image from it. What you need is to create a blank image of a 35x35 size, create an image stream containing the original image, and then put a resized original image in a new blank image.
The health function to complete this task is imageCopyResized (), which is required by the format:
ImageCopyResized ([New Image Handle],
[Original Image Handle],
[New image x],
[new image y],
[Original Image X],
[Original Image Y],
[New Image X], [New Image Y],
[Original Image X],
[Original Image Y]).
/ * Send a head so that the browser knows the content type included in the file * /
Header ("Content-Type: Image / PNG");
/ * Establish variables that save new images and width * /
$ newWidth = 35;
$ newheight = 35;
/ * Establish a new blank image of a given height and width * /
$ newimg = imagecreate ($ newwidth, $ newheight);
/ * Get data from the original image * /
$ Origimg = ImageCreateFromPng ("Test.png");
/ * Copy the image after adjustment, use imageSx (), iMagesY () get the original image in x, y,
ImageCopyResized ($ newimg, $ Origimg, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,/>
/ * Create an image you want to get, release memory * /
ImagePNG ($ newimg);
ImageDestroy ($ newimg);?>
If you save this short script as resized.php, then use the browser to access it, you will see a graphic of a 35x35 size PNG format.
Seven, PHP-based user certification
If you want to make password protection at each script, you can use the header () statement, $ PHP_AUTH_USER, and $ PHP_AUTH_PW to establish a basic authentication scheme, and the usual server-based question / response order is as follows:
1. Users request a file from the server. If this file is protected on the server, a 401 (emptive user) string is returned to the user in the header of the response.
2. After the browser receives this response, the dialog box that requires the user to enter the username / password.
3. Users Enter a username and password in the dialog, and click the OK button to return the information to the server for authentication.
4. If the username and password are valid, the protected file will be open to the user, as long as the user is still using the file, the certification will be effective.
A simple PHP script file can simulate the HTTP's question / response system by sending an appropriate HTTP header that can cause the automatic display user name / password dialog box, PHP inputs the user in the User Name / Password dialog box. Information is stored in $ PHP_AUTH_USER and $ PHP_AUTH_PW, using these two variables, you can compare with usernames / password stored in files such as text files, databases. This example uses two hard-coded values for authentication, but no matter where the username and password are placed, the principles are the same.
/ * Check the value in the PHP_AUTH_USER and $ PHP_AUTH_PW * /
IF ($ PHP_AUTH_USER) || ($ PHP_AUTH_PW))) {
/ * If there is no value, send a header that can initiate the dialog box * /
HEADER (WWW-Authenticate: Basic Realm = "My Private Stuff");
HEADER (http / 1.0 401 unauthorized);
Echo authorization required .;
EXIT;
Else IF (($ PHP_AUTH_USER) && (isset ($ PHP_AUTH_PW))) {
/ * Value in variables, check if they are correct * /
IF ($ PHP_AUTH_USER! = "ValidName") || ($ PHP_AUTH_PW! = "Goodpassword")) {
/ * If there is an incorrectly incorrect input username and password, send a header * / that can raise the dialog
HEADER (WWW-Authenticate: Basic Realm = "My Private Stuff");
HEADER (http / 1.0 401 unauthorized);
Echo authorization required .;
EXIT;
Else IF ($ PHP_AUTH_USER == "VALIDNAME") || ($ PHP_AUTH_PW == "Goodpassword")) {
/ * If the two values are correct, the message is displayed * /
Echo "
youre authorized! p>";
}
}
?>
It should be noted that if you use a file-based protection mechanism, it does not guarantee the security of all files in the directory. It can protect most of the files, if you think it can protect all files in a given directory, your understanding needs to be changed.
Eight, PHP and COM
If you like to take risks, and run the CGI, ISAPI, or Apache module version of the PHP on Windows, you can access the COM function. Ok, explain in detail the work of COM and give Microsoft and many most books. In order to simply understand the COM's function, the following is a common script.
This PHP script starts Microsoft word processing Word on the backend, open a new document, enter some text, save the document, and close the word.
// Establish an index pointing to the new COM component
$ Word = New Com ("Word.Application" OR DIE ("Cant Start Word!");
// Show the version number of the Word currently being used
Echo "Loading Word, V. {$ Word-> Version}
// Set its visibility to 0 (fake) If you want to make it open at the front end, use 1 (true) // to open the application in the forefront, use 1 (true)
$ Word-> Visible = 0;
// Create a new document in Word
$ Word-> Documents-> Add ();
/ / Add text in a new document
$ Word-> Selection-> Typetext ("Testing 1-2-3 ...");
// Save the document in the Windows Temporary Directory
$ Word-> Documents [1] -> Saves ("/ Windows / Temp / Comtest.doc");
// Turn off the connection between the COM assembly
$ Word-> quit ();
/ / Display additional information on the screen
Echo "Check for the File ...";
?>
If you have an intranet website, the data is stored in SQL Server, the user needs these data Excel formats, you can make the necessary SQL query and format the output, then use COM to open Excel, turn the data to Excel format Data, then save the data on the desktop of the user.
Nine, PHP and Java
Another interesting feature of PHP is that it can call the method in the existing Java object so that you can integrate PHP in Java-based applications. If you want to promote PHP applications in your work, this feature is very useful. The result you get is that everything here is based on Java. "
To take advantage of this feature, you must have JVM (Java virtual machine) on your server. If you installed the JDK from Sun, Kaffe, IBM, or BlackDown, JVM has been installed.
When configuring the PHP, you need to add a WITH-JAVA section in the configuration file, then modify part of the php.ini file, the modification of the php.ini file is mainly to add the following:
[Java]
Java.library.path = / path / to / librage
Java.class.path = / classpath /
EXTENSION_DIR = / Path / to / Extensions
EXTENSION = libphp_java.so
It should be noted that the modifications made are related to your installation type, you need to read the readme file in the EXT / JAVA directory, learn how to configure Java features.
Below is an example of how to create a PHP script for a new Java object, which will access and display some Java properties on the display. It is also interesting with the example of COM, and you should give us some inspiration.
$ system = new java ("java.lang.system");
Echo "P> Java Version =". $ system-> getproperty ("java.version"). "
";
Echo "java vendor =". $ system-> getproperty ("java.vendor"). " p>";
?>
If you have Java knowledge, it will help development work, this integrated ability is the relationship between PHP acceptance and growth in the future.
Ten, PHP and XML
The PHP contains an optional XML extension that supports EXPAT resolution, using a function related to XML in PHP, can create an analyst to handle valid XML documents. If you are using the 1.3.7 or higher version of Apache software, you don't need to install additional library files, you need to do just configure the with-xml in PHP. Like Java and COM, the support of XML in PHP is also very interesting, and the growth is also very fast. If you understand Expat or libXML, please join this aspect.