Personal Finance - Home Loans - Online Loans - Personal Loans - Proxy

PDA

View Full Version : PHP to ASP Script Conversion. Help Please


ProductivePC
Nov 7th 2005, 11:16 pm
I have to convert the following script from PHP to ASP. I have no idea where to begin. Can anyone help?


<?php
$i=38;
$CatArray[1] = "Animals";
$CatArray[2] = "Art";
$CatArray[3] = "Astrology";
$CatArray[4] = "Automotive";
$CatArray[5] = "Books";
$CatArray[6] = "Business";
$CatArray[7] = "Computers";
$CatArray[8] = "Dating/Marriage";
$CatArray[9] = "Education";
$CatArray[10] = "Flowers";
$CatArray[11] = "Gift Baskets";
$CatArray[12] = "Gifts";
$CatArray[13] = "Gifts For Baby";
$CatArray[14] = "Gifts For Dad";
$CatArray[15] = "Gifts For Everyone";
$CatArray[16] = "Gifts For Grandparents";
$CatArray[17] = "Gifts For Her";
$CatArray[18] = "Gifts For Him";
$CatArray[19] = "Gifts For Kids";
$CatArray[20] = "Gifts For Mom";
$CatArray[21] = "Gourmet Products";
$CatArray[22] = "Health";
$CatArray[23] = "Holiday Gifts";
$CatArray[24] = "Home and Garden";
$CatArray[25] = "Maps";
$CatArray[26] = "Motor Vehicle";
$CatArray[27] = "Music";
$CatArray[28] = "News & Opinions";
$CatArray[29] = "Other";
$CatArray[30] = "Search Engines";
$CatArray[31] = "Service";
$CatArray[32] = "Service Directory";
$CatArray[33] = "Shopping";
$CatArray[34] = "Travel";
$CatArray[35] = "Vitamins";
$CatArray[36] = "Website Promotion";
$CatArray[37] = "Weddings";
$j=1;
while($j <= $i) {
if (isset($_GET['category'])) {
if (preg_match("/".$_GET['category']."/i",$CatArray[$j],$var)) {
echo("<option value=\"".$CatArray[$j]."\" selected>".$CatArray[$j]."</option>\r\n");
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}
$j++;
}
?>



Thank You,

Wayne

hnn
Nov 7th 2005, 11:20 pm
Microsoft has some PHP to ASP migrators.... Search for them :)

ProductivePC
Nov 7th 2005, 11:30 pm
Thanks.... Any ideas what they are called?

hnn
Nov 7th 2005, 11:35 pm
Sorry.... It was just for ASP.NET

http://www.asp.net/migrationassistants/GettingStarted_PHPtoASPNET.htm

ProductivePC
Nov 7th 2005, 11:36 pm
I tried a couple of convertors but they didn't work
http://www.me-u.com/php-asp/hosting/asp.php

ProductivePC
Nov 8th 2005, 12:16 pm
Okay I have part of this converted but I still have 4 lines left that I am unsure of what the ASP equal to this is?


<%
Dim gv_i
Dim gv_CatArray()
Dim gv_var
Dim gv_j
Dim gv_cat
i=38;
CatArray(1) = "Animals"
CatArray(2) = "Art"
CatArray(3) = "Astrology"
CatArray(4) = "Automotive"
CatArray(5) = "Books"
CatArray(6) = "Business"
CatArray(7) = "Computers"
CatArray(8) = "Dating/Marriage"
CatArray(9) = "Education"
CatArray(10) = "Flowers"
CatArray(11) = "Gift Baskets"
CatArray(12) = "Gifts"
CatArray(13) = "Gifts For Baby"
CatArray(14) = "Gifts For Dad"
CatArray(15) = "Gifts For Everyone"
CatArray(16) = "Gifts For Grandparents"
CatArray(17) = "Gifts For Her"
CatArray(18) = "Gifts For Him"
CatArray(19) = "Gifts For Kids"
CatArray(20) = "Gifts For Mom"
CatArray(21) = "Gourmet Products"
CatArray(22) = "Health"
CatArray(23) = "Holiday Gifts"
CatArray(24) = "Home and Garden"
CatArray(25) = "Maps"
CatArray(26) = "Motor Vehicle"
CatArray(27) = "Music"
CatArray(28) = "News & Opinions"
CatArray(29) = "Other"
CatArray(30) = "Search Engines"
CatArray(31) = "Service"
CatArray(32) = "Service Directory"
CatArray(33) = "Shopping"
CatArray(34) = "Travel"
CatArray(35) = "Vitamins"
CatArray(36) = "Website Promotion"
CatArray(37) = "Weddings"
j=1

' This is where I am having issues

while(j <= i) {

if (isset($_GET['category'])) {
if (preg_match("/".$_GET['category']."/i",$CatArray[$j],$var)) {
echo("<option value=\"".$CatArray[$j]."\" selected>".$CatArray[$j]."</option>\r\n");
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}

j++
}
%>


Can someone point me in the right direction for the following bolded items? I know what they mean in PHP but I don't know how to write them in ASP.

if (isset($_GET['category'])) {
if (preg_match("/".$_GET['category']."/i",$CatArray[$j],$var)) {
echo("<option value=\"".$CatArray[$j]."\" selected>".$CatArray[$j]."</option>\r\n");
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");

ProductivePC
Nov 8th 2005, 4:21 pm
' so as I understand this, it says:
' 1. First, test the variable and if the variable returns true get the category section from the form. However, there is no "category" name in the form. Only "Cat".
' 2. If there is something in the category then use and expression match to find out what it is then once again pull the "category" variable from the form. (See #2)
' a) If there is an expression matched (somebody chose something) then put in for the value of the option select whatever you find in the CatArray(j)
' 2a. Else if there is no expression match (nobody chose anything) then just populate the CatArray(j).
' 3. Else if the variable returns false then just populate the CatArray(j).

[B]Does that sound right?

while(j <= i) {
if (isset($_GET['category'])) {
if (preg_match("/".$_GET['category']."/i",$CatArray[$j],$var)) {
echo("<option value=\"".$CatArray[$j]."\" selected>".$CatArray[$j]."</option>\r\n");
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}
} else {
echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>\r\n");
}

j++
}

draculus
Nov 9th 2005, 2:47 am
Assuming your using a post action for your form:

Do While j <= i
If Request.Form("category") <> "" Then
If Request.Form("category") = CatArray(j) Then
Response.Write("<option value=""" & CatArray(j) & """ selected>" & CatArray(j) & "</option>" & VbCrLf)
Else
Response.Write(("<option value=""" & CatArray(j) & """>" & CatArray(j) & "</option>" & VbCrLf)
EndIf
Else
Response.Write(("<option value=""" & CatArray(j) & """>" & CatArray(j) & "</option>" & VbCrLf)
EndIf
Loop
This is not neccessarily the best code but is a direct translation. I'm assuming your using VBScript. I've not executed this code so you may have to do some tweaking. The bulk of the translation is there.

vectorgraphx
Nov 9th 2005, 6:12 am
slight modification to draculus's code - but i think he's got the idea right on cue.



Do While j <= i
If Request.Form("category") = CatArray(j) Then
Response.Write "<option value=""" & CatArray(j) & """ selected>" & CatArray(j) & "</option>" & VbCrLf
Else
Response.Write "<option value=""" & CatArray(j) & """>" & CatArray(j) & "</option>" & VbCrLf
EndIf

j = j + 1
Loop


a. not sure what the redundant loop was about in the original code - because " If Request.Form("category") = CatArray(j) Then" does pretty much the same thing as "If Request.Form("category") <> "" Then" in this case, since if "Request.Form("category")" is equal to the value in CatArray(j), it must therefore not be "empty".... and the "else" part of both if... then statements are identical - so why the redundancy?

b. i couldn't find a closing parenthesis on part of draculus's example, however i may need more coffee...:D and i generally just use quotes for my response.write statements but that's more a preference thing.

c. j is originally defined as 1 outside of the loop, and is stepped up by one as the loop iterates, thus running through the array range. without the loop stepup - it would be an infinite loop.

also, remove the ";" from the line that reads i=38;. VBscript doesn't need it.

anyways - good luck, hope you get your code going right.



VG

ProductivePC
Nov 9th 2005, 6:33 pm
Thanks Everyone. It works... That was the last page that I needed to convert over to ASP in order to use the ASP scripting code for the coop and have a website that is 100% 1 scripting language... lol... not the 6 scripting languages that we have now... lol