从ASP转换为PHP

时间:2011-01-31 16:26:32

标签: php asp.net code-translation

我被迫与一家仅支持ASP.NET的数据库公司合作,尽管我的雇主非常清楚我只用PHP编写代码并且项目没有时间学习新语法。

文档很少,而且意义薄弱。有人可以帮助翻译此脚本中发生的事情,以便我可以考虑在PHP中进行此操作

<%
 QES.ContentServer cs = new QES.ContentServer();
 string state = "";
 state = Request.Url.AbsoluteUri.ToString();
 Response.Write(cs.GetXhtml(state));
%>

3 个答案:

答案 0 :(得分:1)

QES.ContentServer cs = new QES.ContentServer();

代码实例化类方法ContentServer()

string state = "";

将类型var状态显式化为字符串

state = Request.Url.AbsoluteUri.ToString();

在这里你获得REQUEST URI(如在php中)路径并将其转换为一个行字符串并放入前面提到的字符串statte var

Response.Write(cs.GetXhtml(state));

这里返回消息而不刷新页面(ajax)。

答案 1 :(得分:0)

Request对象包含有关来自客户端的请求的大量信息,即浏览器功能,表单或查询字符串参数,cookie等。在这种情况下,它用于使用{{1}检索绝对URI }。这将是完整的请求路径,包括域,路径,查询字符串值 Request.Url.AbsoluteUri.ToString()对象将从服务器发送的响应流包装回客户端。在这种情况下,它被用于将Response调用的返回值作为响应正文的一部分写入客户端。
cs.GetXhtml(state)似乎是第三方类,并且不是标准.NET框架的一部分,因此您必须访问特定的API文档才能找到QES.ContentServer方法的用途和内容究竟。

因此,简而言之,此脚本从客户端获取请求的完整URI,并在响应中返回GetXhtml的输出。

答案 2 :(得分:0)

在PHP中看起来像这样:

<?php
     $cs = new QES_ContentServer(); //Not a real php class, but doesn't look like a native ASP.NET class either, still, it's a class instantiation, little Google shows it's a class for Qwam E-Content Server.
     $state = "";  //Superfluous in PHP, don't need to define variables before use except in certain logic related circumstances, of course, the ASP.NET could have been done in one line like "string state = Request.Url.AbsoluteUri.ToString();"
     $state = $_SERVER['REQUEST_URI'];  //REQUEST_URI actually isn't the best, but it's pretty close.  Request.Url.AbsoluteUri is the absolute uri used to call the page. REQUEST_URI would return something like /index.php while Request.Url.AbsoluteUri would give http://www.domain.com/index.php
     //$state = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; or something similar might be better in this case given the above
     echo $cs->GetXhtml($state);  //GetXhtml would be a method of QES.ContentServer, Response.Write is like echo or print.
?>