Sending output to the Web browser

The PHP runtime provides an output stream for sending data back to the Web browser. This tutorial shows how to access the output stream and write data into it. The output stream is provided as a Java™ PrintStream object.

1. Add the following Java code to the BigDecimalExtension class:

@XAPIFunction("print_bigdecimal")
public void print(RuntimeContext ctxt) {
        RuntimeServices runtimeServices = getRuntimeServices();
        BigDecimal arg = new BigDecimal(ctxt. 
        getStringArgument(0).getString());
        OutputService outputService = runtimeServices.getOutputService();
        PrintStream ps = outputService.getPrintStream();
        ps.println("Big decimal value: " + arg.toString());
}   

2. Change the sample.php code to exercise the new function.

<?php
$value = '111111111111111';
print_bigdecimal($value);
?>

3. Run the IBM® WebSphere® sMash application and point a Web browser at http://localhost:8080/sample.php

The examples use the RuntimeServices interface, which is the main interface through which an extension interacts with the PHP runtime.

Version 1.1.30763