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>";
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]