gpt4 book ai didi

c# - 在 C# 应用程序中使用 PHP 引擎

转载 作者:搜寻专家 更新时间:2023-10-31 21:44:31 25 4
gpt4 key购买 nike

我想让我的用户能够配置一些 php 脚本来与我的应用程序交互。

我想给用户一个备忘录。用户使用 php 语法编写一些代码,然后按执行。 php 引擎执行代码,所以我可以打印结果。

例如我想写这样的东西:

PHPassembly = Assembly.LoadFrom("php5ts.dll"); 
ExecutePHPScript(PHPassembly,StringContainingAScript);
ResultVar=GetPHPVar(PHPassembly,"ResultVar");

我没有网络服务器。我没有互联网连接。仅适用于 windows 的本地应用程序。

我已尝试加载 php5ts.dll,但编译器说我需要程序集 list 。

有人知道如何与 php 交互吗?

最佳答案

您需要 2 个文件(来自 php-5.3.5-Win32-VC9-x86)php-win.exe 和 php5ts.dll
不仅仅是将这 2 个文件放在您的可执行目录中并运行:

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

关于c# - 在 C# 应用程序中使用 PHP 引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6059786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com