WITM is flawless for accessing Mathematica. But windows users are not so lucky, WITM's default command's are for Linux. This article will help you learn a few tricks, include how to input and capture output in programs with command line interface.
I'm working with Mathematica version 6.01, I didn't test on other versions, but it should be the same.
First, I would like to thank WITM, it showed me there is a command line version of Mathematica. In windows, it would be math.exe, inside the directory where Mathematica is installed. Let's use it find 10!.
$io= array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
);
$location = 'C:\progra~1\wolfra~1\mathem~1\6.0\math.exe';
//The location of mathemacia's math.exe
$p = ' -batchinput -batchoutput';
$process = proc_open($location.$p,$io, $pipes);
$command = '10!'; //the Mathematica command
The above code opens a process, and declares $pipes[0] as the standard input and $pipes[1] as the stand output. Both are used like files.
Run it, it correctly output 3628800. Obviously.
The real reason for me to use Mathematica is to output images of math functions. I reused the command from WITM, made a small improvement so more than one user can use it at the same time.
$command='expr=Plot3D[Sin[x y],{x, 0, 4}, {y, 0, 4}];
head=ToString[Head[expr]];
If[head==ToString[Graphics]
|| head==ToString[SurfaceGraphics]
|| head==ToString[ContourGraphics]
|| head ==ToString[DensityGraphics]
|| head==ToString[GraphicsArray]
|| head==ToString[Graphics3D] ,
Export[IntegerString[Hash[expr,"MD5"],16]<>".gif",
expr,ImageSize->500],
expr]';
if(is_resource($process)){
fwrite($pipes[0], $command."\n");
fclose($pipes[0]);
$content = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}
$filename = substr(substr(trim($content) ,1),0,-1);
The above command will hash the image with MD5 and output it the name to the standard output. The only important thing to do is to also add the directory you want to output to.
The $content have to be trimmed, and remove the double quotes in both side of the string.
Below is the output generated by the combination of the above script and Mathematica.

With this, it's possible to create a Drupal module, include a filter capture the Mathematica commands, run Mathematica and generate result. The image caches in the file system until the author changes the commands. Neatness!
Most other command line program can work with PHP in this way.
Recent comments
21 hours 29 min ago
1 day 6 hours ago
1 day 6 hours ago
1 day 15 hours ago
1 day 22 hours ago
2 days 8 hours ago
4 days 16 hours ago
5 days 13 hours ago
5 days 14 hours ago
5 days 17 hours ago