13.6 Accessing Predefined Java Methods and Classes
TechniqueNo problem! As of PHP 4, Java support is built in: <?php $formatter = new Java("java.text.SimpleDateFormat", "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); print $formatter->format(new Java("java.util.date")); ?> CommentsHere we create a special object, the Java object. The first argument to the constructor is the class we want to work with (in this case, it is java.text.SimpleDateFormat ), and the second argument (as well as the third, fourth, and so on) are the arguments we want to pass to the class specified in the first argument. Having the ability to interface with Java is tremendously useful. For example, much of the XML and XSL functionality in the Open Source world is available only through Java classes. The PHP-Java connection enables you to harness this power for your applications. For example, you could generate XML in PHP and then pass it to a Java XSL formatter class to generate HTML. |