将一些经典 ASP (vbScript) 翻译成 PHP
我正在尝试将经典 ASP (vbScript) 块转换为 PHP。我已经做了诚实的尝试,但我的翻译似乎不正确。有人可以帮我吗?
首先,vbScript 代码:
szTemp = Request.ServerVariables("URL")
aryCrumbs = Split(szTemp,"/")
iMax = Ubound(aryCrumbs)
szCrumbPath = "http://" & Request.ServerVariables("SERVER_NAME")
szTemp = "<a href=""" & szCrumbPath & """ style=""color:#600;"">Home</a>"
For i = 0 To iMax -2
szCrumbPath = szCrumbPath & "/" & aryCrumbs(i)
szTemp = szTemp & " > <a href=""" & szCrumbPath & """ style=""color:#600;"">" & CleanUp(aryCrumbs(i)) & "</a>" 'Note: The > in this line refers to a server request variable.
Next
GetCrumbsArticleCategoryLevel = szTemp & "<span style=""color:#600;""> > " & CleanUp(aryCrumbs(i)) & "</span>"
这是我尝试翻译成 PHP 的代码:
$szTemp = $_SERVER["PATH_INFO"]; // Get current URL path (doesn't include www)
$aryCrumbs = explode("/",$szTemp); // Split path name by slashes into an array
$iMax = count($aryCrumbs); // Count array.
$szCrumbPath = "http://". $_SERVER["HTTP_HOST"]; // Add on http to web server name
$szTemp = '<a href="' . $szCrumbPath . '" style="color:#600;">Home</a>';
for ($i=0; $i<=($iMax-2); $i++) {
$szCrumbPath = $szCrumbPath . "/" . $aryCrumbs[$i];
$szTemp = $szTemp ." > <a href="" . $szCrumbPath . "" style="color:#600;"". ">" . CleanUp($aryCrumbs[$i]) . "</a>";
}
$GetCrumbsArticleCategoryLevel = $szTemp."<span style="color:#600;">> ".CleanUp($aryCrumbs[$i])."</span>";
I'm trying to translate a block of Classic ASP (vbScript) into PHP. I've made an honest attempt, but my translation doesn't appear to be correct. Could anybody help me out?
First, the vbScript Code:
szTemp = Request.ServerVariables("URL")
aryCrumbs = Split(szTemp,"/")
iMax = Ubound(aryCrumbs)
szCrumbPath = "http://" & Request.ServerVariables("SERVER_NAME")
szTemp = "<a href=""" & szCrumbPath & """ style=""color:#600;"">Home</a>"
For i = 0 To iMax -2
szCrumbPath = szCrumbPath & "/" & aryCrumbs(i)
szTemp = szTemp & " > <a href=""" & szCrumbPath & """ style=""color:#600;"">" & CleanUp(aryCrumbs(i)) & "</a>" 'Note: The > in this line refers to a server request variable.
Next
GetCrumbsArticleCategoryLevel = szTemp & "<span style=""color:#600;""> > " & CleanUp(aryCrumbs(i)) & "</span>"
And here's my attempt at translation into PHP:
$szTemp = $_SERVER["PATH_INFO"]; // Get current URL path (doesn't include www)
$aryCrumbs = explode("/",$szTemp); // Split path name by slashes into an array
$iMax = count($aryCrumbs); // Count array.
$szCrumbPath = "http://". $_SERVER["HTTP_HOST"]; // Add on http to web server name
$szTemp = '<a href="' . $szCrumbPath . '" style="color:#600;">Home</a>';
for ($i=0; $i<=($iMax-2); $i++) {
$szCrumbPath = $szCrumbPath . "/" . $aryCrumbs[$i];
$szTemp = $szTemp ." > <a href="" . $szCrumbPath . "" style="color:#600;"". ">" . CleanUp($aryCrumbs[$i]) . "</a>";
}
$GetCrumbsArticleCategoryLevel = $szTemp."<span style="color:#600;">> ".CleanUp($aryCrumbs[$i])."</span>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 PHP 中,为了获得“,您需要用 \ 分隔它,因此“变成 \”
示例:
翻译
我假设您使用的是 Request.ServerVariables("gt "),在 PHP 中相当于 $_SERVER,否则对于 Request.Form,请使用 $_POST 或 $_GET 作为 Request.QueryString。
确保用户是否可以使用 htmlspecialchars() 函数更改您 html 编码的值,否则您为跨站脚本攻击留下了空间 [XSS]
In PHP in order to get a " you need to delimit it with \, so " becomes \"
Example:
Translation
I assumed that you were using Request.ServerVariables("gt"), which in PHP the equivelent is $_SERVER, otherwise for Request.Form use $_POST or $_GET for Request.QueryString.
Make sure if the user can change the values that you html encode using htmlspecialchars() function, otherwise you leave things open for a Cross Site Scripting attack [XSS]