PHP and Java
Java is a very powerful programming tool and its extension library is also very useful. This tutorial mainly describes how to use PHP to call a powerful Java class library (classes ). For your convenience, this tutorial will include Java installation and some basic examples.
Installation in Windows
Step 1: Install JDK. This is very easy. You only need to press enter to install JDK. Perform the following steps.
Add "Path = % PATH %; C: \ jdk1.2.2 \ bin" to the autoexec. BAT file Under Win9x.
Add "; C: \ jdk1.2.2 \ bin" under NT/Win2000 to the environment variable.
This step is very important, so that PHP can correctly find the Java class to be called.
Step 2: Modify your php. ini file.
[Java]
Extension = php_java.dll
Java. Library. Path = c: \ WEB \ PhP4 \ extensions \
Java. Class. Path = "C: \ WEB \ PhP4 \ extensions \ jdk1.2.2 \ php_java.jar; C: \ myclasses"
Add extension = php_java.dll to PhP. ini.
In [Java], set Java. class. path to point to php_java.jar. If you use the new Java class, you should also store the path. In this example, we use the c: \ myclasses directory.
Step 3: create the following PHP file in the test environment:
<?
$ System = new Java ("Java. Lang. system ");
Print "Java version =". $ system-> getproperty ("Java. Version"). "\ n ";
Print "Java vendor =". $ system-> getproperty ("Java. Vendor"). "\ n ";
Print "OS =". $ system-> getproperty ("OS. Name ")."".
$ System-> getproperty ("OS. Version"). "on ".
$ System-> getproperty ("OS. Arch"). "\ n ";
$ Formatter = new Java ("Java. Text. simpledateformat", "eeee,
Mmmm DD, yyyy 'at' H: mm: ss a ZZZZ ");
Print $ formatter-> Format (New Java ("Java. util. date"). "\ n ";
?>
If the installation is correct, you will see the following information:
Java version = 1.2.2
Java vendor = Sun Microsystems Inc.
OS = Windows 95 4.10 on x86
Wednesday, October 18,200 0 at 10:22:45 am China Standard Time
In this way, we have successfully established a PHP runtime environment that can use the Java class, and we can start our next course.