module, you can extend PHP by the power of all available Java classes. To show
you the basics of the Java extension, this article will cover installation and a
few code examples of using PHP and Java together.
4.0.3 Zend Optimiser and JDK 1.2.2 from java.sun.com. We
have also tested this configuration with older versions of the JDK and the
various MS webservers (PWS and IIS) on Windows 95, Windows 98 and NT4.
many questions. It might be useful to check your environment (autoexec.bat in
Windows 9x and System under Control Panel in NT) and make sure the jdk1.x.xbin
directory is in your path.
to your autoexec.bat. On NT add
to the end of the PATH environment variable. It is also important to note in
your autoexec.bat file, the PHP Java extension ignores the JAVA_HOME
and CLASSPATH set up in the environment. This is important because these items must be
set correctly in your php.ini file for the Java extension to work.
[java] extension=php_java.dll java.library.path=c:webphp4extensions java.class.path="c:webphp4extensionsjdk1.2.2php_java.jar;c:myclasses"
extension=php_java.dlldirective with the rest of
the extensions, but it can sit happily under [java]. The
must be set in the location of the php_java.dll, and
include the location of
java.class.pathshould also include the path to other classes you may wish
to use (note the double quotes!).
In these examples, we will be talking about c:myclasses. You should also note
that the single period is ignored by PHP and Java. As far as we know, you cannot set
PHP to look in the current directory for its Java classes.
looks something like this:
<?php $system = new Java("java.lang.System"); print "Java version=".$system->getProperty("java.version")." <br>n"; print "Java vendor=".$system->getProperty("java.vendor")." <p>nn"; print "OS=".$system->getProperty("os.name")." ". $system->getProperty("os.version")." on ". $system->getProperty("os.arch")." <br>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"; ?>
installed everything, you should see some results like:
Java version=1.2.2 Java vendor=Sun Microsystems Inc. OS=Windows 95 4.10 on x86 Wednesday, October 18, 2000 at 10:22:45 AM China Standard Time
classes. Once you have this example working, you have successfully set up the
PHP Java extension.