2

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,

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.