简体   繁体   English

从C#中处理PHP脚本

[英]Processing PHP scripts from within C#

I'm not sure if this has even been done before, but what I am trying to accomplish can't be explained in any great detail, but basically, what I am trying to do is Process PHP scripts from within my C# Windows Forms Application. 我不确定之前是否已经完成此操作,但是我想完成的工作无法得到任何详细解释,但是基本上,我想做的是从C#Windows Forms Application中处理PHP脚本。

I have already created a HTTP server, which works just fine. 我已经创建了一个HTTP服务器,它工作正常。 But now I need to be able to process PHP scripts aswell. 但是现在我还需要能够处理PHP脚本。 We're working on a new privatised language over here, purely for learning and fun. 我们正在这里开发一种新的私有化语言,纯粹是为了学习和娱乐。

(Just a little background, not completely related): (只是一些背景,并不完全相关):

We are now able to create a webpage like so: 现在,我们可以像这样创建一个网页:

Using System.Core,
System.Http,
System.Graphics and System.IO;

    protected void -> Webpage(object homepage)
    {
        // Set Webpage properties.
        homepage.Name = "Home";
        homepage.Size = new Size(960[px], 100[%]);
        homepage.Alignment = new AlignmentType.Vertical;
        homepage.Alignment = new AlignmentType.Horizontal;

        // This is a comment.
        // Create objects to be rendered on the page.

        Text text = new Text();
        FormElements formElements = new FormElements();

        private void -> Webpage.Load(object homepage)
        {
            text.Text = "Please enter your name below:";

            text.Style = new Style(
                Alignment = new AlignmentType.Horizontal,
                Alignment = new AlignmentType.ManualAlignment(15[Y, px]),

                Font = new Font(
                    Font.Family("Arial"),
                    Font.Size = new Size(9[pt], LineHeight(4[px])),
                    Font.Color = new Color.FromArgb(15, 15, 15))
            );

            formElements.CreateElements(TextField["textField"], SubmitButton["submitButton"], Form["form"]);

            textField.Name = "name";
            submitButton.Name = "submit";

            form.Encapsulate(name, submit);

            form.Alignment = new AlignmentType.RelativeTo(text.Bottom);

            Elements[] elements = new Elements[]
            {
                text, form;
            };

            homepage.Display.Element.ElementCollection(elements);
        }

        private void -> Webpage.FormSubmission(object form)
        {
            form.Element(name).OmitSpecialCharacters();

            if(form.Value is not Empty)
            {
                text.Text = "Hello, " + form.Element(name).Value;
            }
        }
    }

The above sample demonstrates the ability to create a whole webpage, style it, and process form input in a nice, clean way. 上面的示例演示了以一种简洁的方式创建整个网页,设置其样式以及处理表单输入的功能。 However, we've come to a complete dead end (trying to support PHP) and we do not wish to delve too far into server-side languages (lack of experience in that area is the main reason), so we would like to be able to "support" PHP scripts from within our WinForms app. 但是,我们已经完全陷入僵局(试图支持PHP),并且我们不希望深入研究服务器端语言(这方面的经验不足是主要原因),因此我们希望成为能够从我们的WinForms应用程序中“支持” PHP脚本。

Anyone know of any way to process PHP scripts from within a C# winforms app? 有谁知道从C#winforms应用程序中处理PHP脚本的任何方法?

Here is a simple http server that supports PHP: MiniHttpd: an HTTP web server library 这是一个支持PHP的简单HTTP服务器: MiniHttpd:HTTP Web服务器库

And here is Phalanger - The PHP Language Compiler for the .NET Framework 这是Phalanger-.NET Framework的PHP语言编译器

Use an HttpWebRequest , and request the url to the PHP page like you would to run the PHP page in your browser. 使用一个HttpWebRequest ,并请求的URL PHP页面就像您运行PHP在浏览器页面。

See here for more info: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx 有关更多信息,请参见此处: http : //msdn.microsoft.com/zh-cn/library/system.net.httpwebrequest.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM