从ASP翻译为PHP
问题描述:
我被迫与仅支持ASP.NET的数据库公司合作,尽管我的雇主非常清楚我只使用PHP编码,而且项目没有时间学习新的句法。从ASP翻译为PHP
文档很少,而且意义不大。有人可以帮忙翻译一下此脚本中发生的事情,让我可以考虑一下在PHP做
<%
QES.ContentServer cs = new QES.ContentServer();
string state = "";
state = Request.Url.AbsoluteUri.ToString();
Response.Write(cs.GetXhtml(state));
%>
答
QES.ContentServer cs = new QES.ContentServer();
代码实例化类方法ContentServer()
string state = "";
显式类型VAR状态作为字符串
state = Request.Url.AbsoluteUri.ToString();
在这里你得到了REQUEST URI(如在php中)路径并将其转换成一个线串,把在之前提到的字符串斯塔泰VAR
Response.Write(cs.GetXhtml(state));
这里不刷新页面(AJAX)返回的消息。
答
Request
对象封装了一系列关于来自客户端的请求的信息,即浏览器功能,表单或查询字符串参数,cookie等。在这种情况下,它用于使用Request.Url.AbsoluteUri.ToString()
来检索绝对URI。这将是完整的请求路径,包括域,路径,查询字符串值。
对象Response
将从服务器发送回来的响应流包装回客户端。在这种情况下,它被用于将作为响应主体的一部分的cs.GetXhtml(state)
调用返回给客户端。 QES.ContentServer
似乎是第三方类,不属于标准.NET框架的一部分,因此您必须访问特定的API文档才能找到GetXhtml
方法的具体用途和用途。
所以,简而言之,这个脚本从客户端获取请求的完整URI并将GetXhtml的输出返回给响应。
答
它看起来像这样在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.
?>
是什么ContentServer()呢? – 2011-01-31 16:36:13