1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP to ASP Script Conversion. Help Please

Discussion in 'C#' started by ProductivePC, Nov 7, 2005.

  1. #1
    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++;
    }
    ?>
    
    PHP:

    Thank You,
    SEMrush
    Wayne
     
    ProductivePC, Nov 7, 2005 IP
    SEMrush
  2. hnn

    hnn Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Microsoft has some PHP to ASP migrators.... Search for them :)
     
    hnn, Nov 7, 2005 IP
  3. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks.... Any ideas what they are called?
     
    ProductivePC, Nov 7, 2005 IP
  4. hnn

    hnn Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hnn, Nov 7, 2005 IP
  5. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ProductivePC, Nov 7, 2005 IP
  6. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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 ([B]isset($_GET['category'])[/B]) {
                 if ([B]preg_match("/".$_GET['category']."/i",$CatArray[$j],$var)[/B]) {  
                            echo("<option value=\"".$CatArray[$j]."\" selected>".$CatArray[$j]."</option>[B]\r\n[/B]");
                 } else {
                           echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>[B]\r\n[/B]");
                 }
     } else {
                echo("<option value=\"".$CatArray[$j]."\">".$CatArray[$j]."</option>[B]\r\n[/B]");
            }
    
     j++
    }
    %>
    
    Code (markup):
    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 8, 2005 IP
  7. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ' 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) [because this is a loop continue counting up]
    ' 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).

    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++
    }
     
    ProductivePC, Nov 8, 2005 IP
  8. draculus

    draculus Peon

    Messages:
    63
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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
    Code (markup):
    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.
     
    draculus, Nov 9, 2005 IP
  9. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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
    
    Code (markup):
    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
     
    vectorgraphx, Nov 9, 2005 IP
  10. ProductivePC

    ProductivePC Peon

    Messages:
    362
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #10
    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
     
    ProductivePC, Nov 9, 2005 IP