问题
I have a sample PHP class which I would like to Utilize in my Java Application.
We have decided to use Quercus as a Libary for doing the Integration.
Can some one let me know How can I call a PHP class from Java Code using Quercus.
For Example.
PHP class name is calculator.php and it has one method say sum() which expects 2 numbers to be passed and It will do the summation of those number.
Please let me know the sample code which can be coded to achive the same.
Thanks,
回答1:
You should look at QuercusEngine
import com.caucho.quercus.QuercusEngine;
QuercusEngine engine = new QuercusEngine();
engine.setOutputStream(System.out);
engine.executeFile("src/test.php");
Other examples
The only needed jars are resin.jar and servlet-api.jar.
回答2:
It seems that you can't usefully instantiate a QuercusEngine these days. Instead:
import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;
QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
You then probably want engine.eval(reader);
来源:https://stackoverflow.com/questions/5298123/php-call-from-java-using-quercus