DekGenius.com
Previous Section  < Day Day Up >  Next Section

13.14 Talking to Other Languages

With various extensions, the PHP interpreter can run programs written in other languages such as Java and Perl. On Windows, the PHP interpreter can access COM objects.

The Perl extension is for PHP 5 only. Example 13-18 demonstrates a very simple program that uses the Perl extension to print a message. Typically, you'd use the Perl extension to access some existing Perl libraries that you have.

Example 13-18. Using Perl from PHP
$perl = new Perl( );

$perl->eval('print "This is Perl!";');

Example 13-18 prints:

This is Perl!

Example 13-19 shows a simple Java example.

Example 13-19. Using Java from 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'));

In the afternoon of October 20, 2004, Example 13-19 prints:

Wednesday, October 20, 2004 at 1:30:00 PM Eastern Daylight Time

Read about the Perl extension at http://www.zend.com/php5/articles/php5-perl.php, and the Java and COM extensions in the PHP Manual (http://www.php.net/java and http://www.php.net/com).

    Previous Section  < Day Day Up >  Next Section