Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the php engine inside a c# application

Tags:

c#

php

winforms

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 execute. 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?

like image 898
Redax Avatar asked Dec 15 '25 14:12

Redax


1 Answers

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);
like image 158
cichy Avatar answered Dec 17 '25 07:12

cichy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!