将一些经典 ASP (vbScript) 翻译成 PHP

发布于 2024-11-17 01:46:38 字数 1697 浏览 3 评论 0原文

我正在尝试将经典 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 & "  &gt; <a href=""" & szCrumbPath & """ style=""color:#600;"">" & CleanUp(aryCrumbs(i)) & "</a>"    'Note: The &gt; in this line refers to a server request variable. 
Next

GetCrumbsArticleCategoryLevel = szTemp & "<span style=""color:#600;"">  &gt; " & 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=&quot;color:#600;&quot;>Home</a>'; 

for ($i=0; $i<=($iMax-2); $i++) {

$szCrumbPath = $szCrumbPath . "/" . $aryCrumbs[$i];
$szTemp = $szTemp ." &gt; <a href=&quot;" . $szCrumbPath . "&quot; style=&quot;color:#600;&quot;". ">" . CleanUp($aryCrumbs[$i]) . "</a>";
}

$GetCrumbsArticleCategoryLevel = $szTemp."<span style=&quot;color:#600;&quot;>&gt; ".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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦魇绽荼蘼 2024-11-24 01:46:38

在 PHP 中,为了获得“,您需要用 \ 分隔它,因此“变成 \”

示例:

$szTemp = "<a href=\"" . $szCrumbPath . "\" style=\"color: #600\">Home</a>";

翻译

我假设您使用的是 Request.ServerVariables("gt "),在 PHP 中相当于 $_SERVER,否则对于 Request.Form,请使用 $_POST 或 $_GET 作为 Request.QueryString。

确保用户是否可以使用 htmlspecialchars() 函数更改您 html 编码的值,否则您为跨站脚本攻击留下了空间 [XSS]

$szTemp = $_SERVER['REQUEST_URI'];
$aryCrumbs = explode("/", $szTemp);
$iMax = count($aryCrumbs);

$szCrumbPath = "http://". $_SERVER["HTTP_HOST"];
$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>"; //The htmlspecialchars prevents a XSS attack
}
$GetCrumbsArticleCategoryLevel = $szTemp . "<span style=\"color:#600\"> > " . CleanUp($aryCrumbs[$i]) . "</span>";

In PHP in order to get a " you need to delimit it with \, so " becomes \"

Example:

$szTemp = "<a href=\"" . $szCrumbPath . "\" style=\"color: #600\">Home</a>";

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]

$szTemp = $_SERVER['REQUEST_URI'];
$aryCrumbs = explode("/", $szTemp);
$iMax = count($aryCrumbs);

$szCrumbPath = "http://". $_SERVER["HTTP_HOST"];
$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>"; //The htmlspecialchars prevents a XSS attack
}
$GetCrumbsArticleCategoryLevel = $szTemp . "<span style=\"color:#600\"> > " . CleanUp($aryCrumbs[$i]) . "</span>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文