Hi.
I don't know whether this is the right place asking this question or no.

I want to know, is it possible to use PHP code into JAVA code?

if yes how?

Recommended Answers

All 4 Replies

Hi.
I don't know whether this is the right place asking this question or no.

I want to know, is it possible to use PHP code into JAVA code?

if yes how?

There are quite a few implementations of PHP in pure Java.

See:
http://www.caucho.com/resin-3.0/quercus/
http://www.projectzero.org/
http://www.sun.com/download/products.xml?id=45c26bc9

If you need something simple, you can just built the PHP executable on your Java Server, and then when you need to run some PHP, execute a system command within Java code that has the PHP executable execute some PHP for you. (write the command to stdin and read stdout)
eg:
http://www.wellho.net/resources/ex.php4?item=j714/Discfree.java
http://www.devdaily.com/java/edu/pj/pj010016/pj010016.shtml

the command would look like:

(on linux)

/usr/bin/php -r "echo 'hello from php binary';"

where "echo 'hello from php binary';" is the command sent to php.

Thanks very much for the information, still I am confused.

I want to know it is possible to use something like the following in a .java file.

System.out.println("<?php echo "<h1> Welocme</h1>" ?>");

Thanks very much for the information, still I am confused.

I want to know it is possible to use something like the following in a .java file.

System.out.println("<?php echo "<h1> Welocme</h1>" ?>");

It can be done. But you'd have to look at the documentation for the PHP interpreters written in Java to see if they support that.

If they don't they you could still write your own Java code that would reparse the output from Java with the PHP interpreter before it is sent to HTTP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.