I would like to give my users the ability to configure some php script to interact with my applycation.
I would like to give the user a Memo. The user writes some code with a php syntax, then press execu开发者_如何学JAVAte. The php engine executes the code, so I can print a result.
For example I would like to write something like:
PHPassembly = Assembly.LoadFrom("php5ts.dll");
ExecutePHPScript(PHPassembly,StringContainingAScript);
ResultVar=GetPHPVar(PHPassembly,"ResultVar");
I don't have a web server. I don't have an internet connection. Only a local application for windows.
I have tryed to load the php5ts.dll, but the compiler says that I need an assembly manifest.
Someone knows how to interact with php?
You need 2 files (from php-5.3.5-Win32-VC9-x86) php-win.exe and php5ts.dll
Than just place those 2 files in you executable directory and run:
string code = "echo 'test';";
System.Diagnostics.Process ProcessObj = new System.Diagnostics.Process();
ProcessObj.StartInfo.FileName = "php-win.exe";
ProcessObj.StartInfo.Arguments = String.Format("-r \"{0}\"", code);
ProcessObj.StartInfo.UseShellExecute = false;
ProcessObj.StartInfo.CreateNoWindow = true;
ProcessObj.StartInfo.RedirectStandardOutput = true;
ProcessObj.Start();
ProcessObj.WaitForExit();
string Result = ProcessObj.StandardOutput.ReadToEnd();
MessageBox.Show(Result);
You can try hosting the php runtime locally. There are preconfigured packages for that, with PHP + Apache, like xampp and WampServer. This way, you can call it via HTTP requests to localhost
(such an approach is discussed here).
With a bit of configuration,you could execute your code against php running on the command line.
See php.net for more info
in search of something similar myself I found this question.
maybe port and include code from http://ph7.symisc.net/index.html if you don't need too fancy php stuff?
精彩评论