开发者

How to retrieve a variable of php file with using java?

I am triying to get a variable from php file with using java code. How c开发者_StackOverflow社区an I do that? Thank u all...


I don't think you can do that (at least not easy).

You would have to call your java program from within your php program and supply all parameters you got from the database to the java program. Using a transfer language like SOAP could do that.

If it is possible in your environment I strongly suggest you quit using them both and instead settle on one of this two languages instead. Java has fine database support and most of the things you can do in java can be done in php as well.

If that’s not possible, using SOAP or (depending on the situation) HTTP Servlet calls or a command line call will give you the ability to transfer parameters from php to java and visa-verse.


Assuming you are talking about JavaScript instead of Java, the best way to do this is using AJAX. You need two pieces of code for this:

  1. One piece in PHP that will print the variable (if it's a complex variable, a dataformat like JSON or XML is recommended)

  2. One piece in Javascript that will call the .php script that prints the variable, and puts the variable into javascript (but don't use eval() for this).

Read more about AJAX and PHP at the w3schools intro or the more advanced example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜