This is a discussion on rewrite asp code to php within the PHP Language forums, part of the PHP Programming Forums category; hello i'm trying to translate this asp code to php, but i can't get it work right. could ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
hello
i'm trying to translate this asp code to php, but i can't get it work right. could anyone help me? thanks! a. ASP CODE --------------------- <% Public mArrContent 'Build up the array Redim mArrContent(30,5) mArrContent(1 , 0) = 0 mArrContent(1 , 1) = 42 mArrContent(1 , 2) = "folder" mArrContent(1 , 3) = "Leistungen" mArrContent(1 , 4) = 34 mArrContent(2 , 0) = 1 mArrContent(2 , 1) = 48 mArrContent(2 , 2) = "page" mArrContent(2 , 3) = "Evaluation" mArrContent(2 , 4) = 42 mArrContent(3 , 0) = 1 mArrContent(3 , 1) = 47 mArrContent(3 , 2) = "page" mArrContent(3 , 3) = "Forschung" mArrContent(3 , 4) = 42 mArrContent(4 , 0) = 1 mArrContent(4 , 1) = 49 mArrContent(4, 2) = "page" mArrContent(4 , 3) = "Beratung" mArrContent(4 , 4) = 42 mArrContent(5 , 0) = 0 mArrContent(5 , 1) = 43 mArrContent(5 , 2) = "folder" mArrContent(5 , 3) = "Themen" mArrContent(5 , 4) = 34 mArrContent(6 , 0) = 1 mArrContent(6 , 1) = 51 mArrContent(6, 2) = "page" mArrContent(6 , 3) = "Verkehr, Umwelt & Energie" mArrContent(6 , 4) = 43 mArrContent(7 , 0) = 1 mArrContent(7 , 1) = 52 mArrContent(7 , 2) = "page" mArrContent(7 , 3) = "Soziale Sicherheit & Integration" mArrContent(7 , 4) = 43 mArrContent(8 , 0) = 1 mArrContent(8 , 1) = 53 mArrContent(8 , 2) = "page" mArrContent(8 , 3) = "Bildung & Familie" mArrContent(8 , 4) = 43 mArrContent(9 , 0) = 1 mArrContent(9 , 1) = 54 mArrContent(9 , 2) = "page" mArrContent(9 , 3) = "Reformen" mArrContent(9 , 4) = 43 mArrContent(10 , 0) = 1 mArrContent(10 , 1) = 147 mArrContent(10 , 2) = "page" mArrContent(10 , 3) = "Gesundheit" mArrContent(10 , 4) = 43 mArrContent(11 , 0) = 1 mArrContent(11 , 1) = 251 mArrContent(11 , 2) = "page" mArrContent(11 , 3) = "test" mArrContent(11, 4) = 43 mArrContent(12 , 0) = 0 mArrContent(12 , 1) = 45 mArrContent(12 , 2) = "folder" mArrContent(12 , 3) = "Projekte & Publikationen" mArrContent(12 , 4) = 34 mArrContent(13 , 0) = 1 mArrContent(13 , 1) = 113 mArrContent(13 , 2) = "folder" mArrContent(13 , 3) = "Projekte" mArrContent(13 , 4) = 45 mArrContent(14 , 0) = 2 mArrContent(14 , 1) = 138 mArrContent(14 , 2) = "page" mArrContent(14 , 3) = "Test Projekt" mArrContent(14 , 4) = 113 mArrContent(15 , 0) = 2 mArrContent(15 , 1) = 154 mArrContent(15 , 2) = "page" mArrContent(15 , 3) = "Noch ein Testprojekt" mArrContent(15 , 4) = 113 mArrContent(16 , 0) = 0 mArrContent(16 , 1) = 125 mArrContent(16, 2) = "folder" mArrContent(16, 3) = "Publikationen" mArrContent(16, 4) = 45 mArrContent(17, 0) = 0 mArrContent(17, 1) = 117 mArrContent(17, 2) = "page" mArrContent(17, 3) = "Aktuelle Projekte & Publikationen" mArrContent(17, 4) = 45 mArrContent(18, 0) = 0 mArrContent(18, 1) = 118 mArrContent(18, 2) = "page" mArrContent(18, 3) = "Verkehr, Umwelt & Energie" mArrContent(18, 4) = 45 mArrContent(19, 0) = 0 mArrContent(19, 1) = 119 mArrContent(19, 2) = "page" mArrContent(19, 3) = "Soziale Sicherheit & Integration" mArrContent(19, 4) = 45 mArrContent(20, 0) = 0 mArrContent(20, 1) = 120 mArrContent(20, 2) = "page" mArrContent(20, 3) = "Bildung & Familie" mArrContent(20, 4) = 45 mArrContent(21, 0) = 0 mArrContent(21, 1) = 121 mArrContent(21, 2) = "page" mArrContent(21, 3) = "Reform & Internationale Entwicklung" mArrContent(21, 4) = 45 mArrContent(22, 0) = 0 mArrContent(22, 1) = 46 mArrContent(22, 2) = "folder" mArrContent(22, 3) = "Portrait" mArrContent(22, 4) = 34 mArrContent(23, 0) = 1 mArrContent(23, 1) = 143 mArrContent(23, 2) = "page" mArrContent(23, 3) = "Verst‰ndnis" mArrContent(23, 4) = 46 mArrContent(24, 0) = 1 mArrContent(24, 1) = 58 mArrContent(24, 2) = "page" mArrContent(24, 3) = "Team" mArrContent(24, 4) = 46 mArrContent(25, 0) = 1 mArrContent(25, 1) = 144 mArrContent(25, 2) = "page" mArrContent(25, 3) = "Auftraggeber" mArrContent(25, 4) = 46 mArrContent(26, 0) = 1 mArrContent(26, 1) = 146 mArrContent(26, 2) = "page" mArrContent(26, 3) = "Partner im Ausland" mArrContent(26, 4) = 46 mArrContent(27, 0) = 1 mArrContent(27, 1) = 145 mArrContent(27, 2) = "page" mArrContent(27, 3) = "Stellenangebot" mArrContent(27, 4) = 46 mArrContent(28, 0) = 1 mArrContent(28, 1) = 262 mArrContent(28, 2) = "page" mArrContent(28, 3) = "Test" mArrContent(28, 4) = 46 mArrContent(29, 0) = 1 mArrContent(29, 1) = 263 mArrContent(29, 2) = "page" mArrContent(29, 3) = "so" mArrContent(29, 4) = 46 mArrContent(30, 0) = 0 mArrContent(30, 1) = 264 mArrContent(30, 2) = "page" mArrContent(30, 3) = "Sitemap" mArrContent(30, 4) = 34 'Call the function to Generate the Nested Array marrMain = GenerateNestedArray(mArrContent) 'Call the function to Generate the HTML script Call GenerateHTML(marrMain) '/********************************** 'This is the function that generate 'the nested array based on a given 'multidimensional array '/********************************** Function GenerateNestedArray(ArrContent) Dim arrMain Dim arrSub Dim arrSubContent Redim arrSub(5) Redim arrMain(0) Dim lngCount For i = 1 to UBound(arrContent) Redim arrSubContent(0) if arrContent(i,4) = 34 then lngCount = lngCount + 1 Redim Preserve arrMain(lngCount) For j = 0 to 4 arrSub(j) = ArrContent(i,j) next arrSub(5) = arrSubContent arrMain(lngCount) = arrSub else for j = 1 to Ubound(arrMain) For k = 0 to 4 arrSub(k) = arrContent(i,k) next arrSub(5) = arrSubContent if FindParent(arrMain(j), arrSub) = true then exit for End if Next end if next GenerateNestedArray = arrMain end function '/********************************** 'This is the function that 'recursively find the parent 'folder of a given page or folder 'and then places the data into 'the fifth element of the parent array '/********************************** Function FindParent(arrParent, arrContent) On error resume next Dim arrSub(5) Dim arrTemp(5) Dim arrSubContent(0) Dim arrSubArray Dim lngCount if arrParent(1) = arrContent(4) then For j = 0 to 4 arrSub(j) = arrContent(j) next arrSub(5) = arrSubContent if Ubound(arrParent(5)) = 0 then lngCount = 1 redim ArrSubArray(1) arrSubArray(1) = arrSub else lngCount = Ubound(arrParent(5)) + 1 Redim arrSubArray(lngCount) for j = 1 to lngCount -1 arrSubArray(j)= arrParent(5)(j) Next arrSubArray(lngCount) = arrContent end if arrParent(5) = arrSubArray FindParent = true Exit Function elseif Ubound(arrParent(5)) > 0 then for i = 1 to Ubound(arrParent(5)) blnFindParent = FindParent(arrParent(5)(i), arrContent) if blnFindParent = true then Exit function end if next end if FindParent = false End Function '/********************************** 'This is the function that 'Generates the HTML script 'which then recursively call 'WriteData function to separate 'each group '/********************************** Function GenerateHTML(arrMain) For i = 1 to Ubound(arrMain) Call WriteData(arrMain(i)) response.write "<br>" next End function Function WriteData(arrData) on error resume next Dim arrSub(5) response.write "<ul>" response.write "<li>" & arrData(2) & " " & arrData(3) if Ubound(arrData(5)) > 0 then for j=1 to Ubound(arrData(5)) Call WriteData(arrData(5)(j)) next End if response.write "</li>" response.write "</ul>" End function %> PHP CODE ----------------------- <? //Build up the array $mArrContent[1][0]=0; $mArrContent[1][1]=42; $mArrContent[1][2]="folder"; $mArrContent[1][3]="Leistungen"; $mArrContent[1][4]=34; $mArrContent[2][0]=1; $mArrContent[2][1]=48; $mArrContent[2][2]="page"; $mArrContent[2][3]="Evaluation"; $mArrContent[2][4]=42; $mArrContent[3][0]=1; $mArrContent[3][1]=47; $mArrContent[3][2]="page"; $mArrContent[3][3]="Forschung"; $mArrContent[3][4]=42; $mArrContent[4][0]=1; $mArrContent[4][1]=49; $mArrContent[4][2]="page"; $mArrContent[4][3]="Beratung"; $mArrContent[4][4]=42; $mArrContent[5][0]=0; $mArrContent[5][1]=43; $mArrContent[5][2]="folder"; $mArrContent[5][3]="Themen"; $mArrContent[5][4]=34; $mArrContent[6][0]=1; $mArrContent[6][1]=51; $mArrContent[6][2]="page"; $mArrContent[6][3]="Verkehr, Umwelt & Energie"; $mArrContent[6][4]=43; $mArrContent[7][0]=1; $mArrContent[7][1]=52; $mArrContent[7][2]="page"; $mArrContent[7][3]="Soziale Sicherheit & Integration"; $mArrContent[7][4]=43; $mArrContent[8][0]=1; $mArrContent[8][1]=53; $mArrContent[8][2]="page"; $mArrContent[8][3]="Bildung & Familie"; $mArrContent[8][4]=43; $mArrContent[9][0]=1; $mArrContent[9][1]=54; $mArrContent[9][2]="page"; $mArrContent[9][3]="Reformen"; $mArrContent[9][4]=43; $mArrContent[10][0]=1; $mArrContent[10][1]=147; $mArrContent[10][2]="page"; $mArrContent[10][3]="Gesundheit"; $mArrContent[10][4]=43; $mArrContent[11][0]=1; $mArrContent[11][1]=251; $mArrContent[11][2]="page"; $mArrContent[11][3]="test"; $mArrContent[11][4]=43; $mArrContent[12][0]=0; $mArrContent[12][1]=45; $mArrContent[12][2]="folder"; $mArrContent[12][3]="Projekte & Publikationen"; $mArrContent[12][4]=34; $mArrContent[13][0]=1; $mArrContent[13][1]=113; $mArrContent[13][2]="folder"; $mArrContent[13][3]="Projekte"; $mArrContent[13][4]=45; $mArrContent[14][0]=2; $mArrContent[14][1]=138; $mArrContent[14][2]="page"; $mArrContent[14][3]="Test Projekt"; $mArrContent[14][4]=113; $mArrContent[15][0]=2; $mArrContent[15][1]=154; $mArrContent[15][2]="page"; $mArrContent[15][3]="Noch ein Testprojekt"; $mArrContent[15][4]=113; $mArrContent[16][0]=0; $mArrContent[16][1]=125; $mArrContent[16][2]="folder"; $mArrContent[16][3]="Publikationen"; $mArrContent[16][4]=45; $mArrContent[17][0]=0; $mArrContent[17][1]=117; $mArrContent[17][2]="page"; $mArrContent[17][3]="Aktuelle Projekte & Publikationen"; $mArrContent[17][4]=45; $mArrContent[18][0]=0; $mArrContent[18][1]=118; $mArrContent[18][2]="page"; $mArrContent[18][3]="Verkehr, Umwelt & Energie"; $mArrContent[18][4]=45; $mArrContent[19][0]=0; $mArrContent[19][1]=119; $mArrContent[19][2]="page"; $mArrContent[19][3]="Soziale Sicherheit & Integration"; $mArrContent[19][4]=45; $mArrContent[20][0]=0; $mArrContent[20][1]=120; $mArrContent[20][2]="page"; $mArrContent[20][3]="Bildung & Familie"; $mArrContent[20][4]=45; $mArrContent[21][0]=0; $mArrContent[21][1]=121; $mArrContent[21][2]="page"; $mArrContent[21][3]="Reform & Internationale Entwicklung"; $mArrContent[21][4]=45; $mArrContent[22][0]=0; $mArrContent[22][1]=46; $mArrContent[22][2]="folder"; $mArrContent[22][3]="Portrait"; $mArrContent[22][4]=34; $mArrContent[23][0]=1; $mArrContent[23][1]=143; $mArrContent[23][2]="page"; $mArrContent[23][3]="Verst‰ndnis"; $mArrContent[23][4]=46; $mArrContent[24][0]=1; $mArrContent[24][1]=58; $mArrContent[24][2]="page"; $mArrContent[24][3]="Team"; $mArrContent[24][4]=46; $mArrContent[25][0]=1; $mArrContent[25][1]=144; $mArrContent[25][2]="page"; $mArrContent[25][3]="Auftraggeber"; $mArrContent[25][4]=46; $mArrContent[26][0]=1; $mArrContent[26][1]=146; $mArrContent[26][2]="page"; $mArrContent[26][3]="Partner im Ausland"; $mArrContent[26][4]=46; $mArrContent[27][0]=1; $mArrContent[27][1]=145; $mArrContent[27][2]="page"; $mArrContent[27][3]="Stellenangebot"; $mArrContent[27][4]=46; $mArrContent[28][0]=1; $mArrContent[28][1]=262; $mArrContent[28][2]="page"; $mArrContent[28][3]="Test"; $mArrContent[28][4]=46; $mArrContent[29][0]=1; $mArrContent[29][1]=263; $mArrContent[29][2]="page"; $mArrContent[29][3]="so"; $mArrContent[29][4]=46; $mArrContent[30][0]=0; $mArrContent[30][1]=264; $mArrContent[30][2]="page"; $mArrContent[30][3]="Sitemap"; $mArrContent[30][4]=34; //Call the function to Generate the Nested Array $marrMain=GenerateNestedArray($mArrContent); //Call the function to Generate the HTML script print GenerateHTML($marrMain); ///********************************** // This is the function that generate // the nested array based on a given // multidimensional array ///********************************** function GenerateNestedArray($arrContent) { $arrMain = array(); $arrSub = array(); $arrSubContent = array(); for ($i=1;$i<=count($arrContent);$i++) { if ($arrContent[$i][4]==34) { $lngCount++; for ($j=0;$j<=4;$j++) { $arrSub[$j] = $arrContent[$i][$j]; } $arrSub[5] = $arrSubContent; $arrMain[$lngCount] = $arrSub; } else { for ($j=0;$j<count($arrMain);$j++) { for($k=0;$k<4;$k++){ $arrSub[$k] = $arrContent[$i][$k]; } $arrSub[5] = $arrSubContent; if (FindParent($arrMain[$j],$arrSub)===false) { break; } } } } return $arrMain; } ///********************************** // This is the function that // recursively find the parent // folder of a given page or folder // and then places the data into // the fifth element of the parent array ///********************************** function FindParent($arrParent,$arrContent) { $arrSub = array(); $arrSubContent = array(); $arrSubArray = array(); if ($arrParent[1]==$arrContent[4]) { for ($j=0;$j<=4;$j++) { $arrSub[$j] = $arrContent[$j]; } $arrSub[5] = $arrSubContent; if(count($arrParent[5])==0) { $lngCount = 1; $arrSubArray[] = $arrSub; } else { $lngCount = count($arrParent[5])+1; for($j=1;$i<=$lngCount-1;$j++) { $arrSubArray[$j] = $arrParent[5][$j]; } $arrSubArray[$j] = $arrContent; } $arrParent[5] = $arrSubArray; return true; } else if (count($arrParent[5])>0) { for ($i=1;$i<=count($arrParent[5]);$i++) { $blnFindParent = FindParent($arrParent[5][$i],$arrContent); if ($blnFindParent == true) { break; } } } return false; } ///********************************** //This is the function that //Generates the HTML script //which then recursively call //WriteData function to separate //each group ///********************************** function GenerateHTML($arrMain) { for ($i=1; $i<=count($arrMain); $i=$i+1) { WriteData($arrMain[$i]); print "<br>"; } return $function_ret; } function WriteData($arrData) { extract($GLOBALS); print "<ul>"; print "<li>".$arrData[2]." ".$arrData[3]; if (count($arrData[5])>0) { for ($j=1; $j<=count($arrData[5]); $j=$j+1) { WriteData($arrData[5]($j)); } } print "</li>"; print "</ul>"; } ?> |
|
|||
|
Aldo wrote:
> i'm trying to translate this asp code to php, but i can't get it work right. > could anyone help me? thanks! [snip code] maybe http://www.google.com/search?q=asp%20to%20php -- USENET would be a better place if everybody read: http://www.expita.com/nomime.html http://www.netmeister.org/news/learn2quote2.html http://www.catb.org/~esr/faqs/smart-questions.html |
|
|||
|
*** Aldo escribió/wrote (11 Oct 2004 10:16:16 -0700):
> i'm trying to translate this asp code to php, but i can't get it work right. > could anyone help me? Maybe if you could shorten the question... Nobody's going to check six hundred lines of code for you. -- -+ Álvaro G. Vicario - Burgos, Spain +- http://www.demogracia.com (la web de humor barnizada para la intemperie) ++ Las dudas informáticas recibidas por correo irán directas a la papelera -+ I'm not a free help desk, please don't e-mail me your questions -- |
|
|||
|
Yes i think you're right ;-)…
here the two functions I can't get to work in php. the array who is feeding the function "GenerateNestedArray" has this structure: $mArrContent[1][0]=0; 'counter $mArrContent[1][1]=42; 'id $mArrContent[1][2]="folder"; 'folder or page $mArrContent[1][3]="Leistungen"; 'title $mArrContent[1][4]=34; 'parent id my goal is to build a multidimensional array with the right folder structure ASP ------------- 'Call the function to Generate the Nested Array marrMain = GenerateNestedArray(mArrContent) '/********************************** 'This is the function that generate 'the nested array based on a given 'multidimensional array '/********************************** Function GenerateNestedArray(ArrContent) Dim arrMain Dim arrSub Dim arrSubContent Redim arrSub(5) Redim arrMain(0) Dim lngCount For i = 1 to UBound(arrContent) Redim arrSubContent(0) if arrContent(i,4) = 34 then lngCount = lngCount + 1 Redim Preserve arrMain(lngCount) For j = 0 to 4 arrSub(j) = ArrContent(i,j) next arrSub(5) = arrSubContent arrMain(lngCount) = arrSub else for j = 1 to Ubound(arrMain) For k = 0 to 4 arrSub(k) = arrContent(i,k) next arrSub(5) = arrSubContent if FindParent(arrMain(j), arrSub) = true then exit for End if Next end if next GenerateNestedArray = arrMain end function '/********************************** 'This is the function that 'recursively find the parent 'folder of a given page or folder 'and then places the data into 'the fifth element of the parent array '/********************************** Function FindParent(arrParent, arrContent) On error resume next Dim arrSub(5) Dim arrTemp(5) Dim arrSubContent(0) Dim arrSubArray Dim lngCount if arrParent(1) = arrContent(4) then For j = 0 to 4 arrSub(j) = arrContent(j) next arrSub(5) = arrSubContent if Ubound(arrParent(5)) = 0 then lngCount = 1 redim ArrSubArray(1) arrSubArray(1) = arrSub else lngCount = Ubound(arrParent(5)) + 1 Redim arrSubArray(lngCount) for j = 1 to lngCount -1 arrSubArray(j)= arrParent(5)(j) Next arrSubArray(lngCount) = arrContent end if arrParent(5) = arrSubArray FindParent = true Exit Function elseif Ubound(arrParent(5)) > 0 then for i = 1 to Ubound(arrParent(5)) blnFindParent = FindParent(arrParent(5)(i), arrContent) if blnFindParent = true then Exit function end if next end if FindParent = false End Function PHP -------------------- //Call the function to Generate the Nested Array $marrMain=GenerateNestedArray($mArrContent); //Call the function to Generate the HTML script GenerateHTML($marrMain); ///********************************** // This is the function that generate // the nested array based on a given // multidimensional array ///********************************** function GenerateNestedArray($arrContent) { $arrMain = array(); $arrSub = array(); $arrSubContent = array(); for ($i=1;$i<=count($arrContent);$i++) { if ($arrContent[$i][4]==34) { $lngCount++; for ($j=0;$j<=4;$j++) { $arrSub[$j] = $arrContent[$i][$j]; } $arrSub[5] = $arrSubContent; $arrMain[$lngCount] = $arrSub; } else { for ($j=1;$j<=count($arrMain);$j++) { for($k=0;$k<4;$k++){ $arrSub[$k] = $arrContent[$i][$k]; } $arrSub[5] = $arrSubContent; if (FindParent($arrMain[$j],$arrSub)===false) { break; } } } } return $arrMain; } ///********************************** // This is the function that // recursively find the parent // folder of a given page or folder // and then places the data into // the fifth element of the parent array ///********************************** function FindParent($arrParent,$arrContent) { $arrSub = array(); $arrSubContent = array(); $arrSubArray = array(); if ($arrParent[1]==$arrContent[4]) { for ($j=0;$j<=4;$j++) { $arrSub[$j] = $arrContent[$j]; } $arrSub[5] = $arrSubContent; if(count($arrParent[5])==0) { $lngCount = 1; $arrSubArray[] = $arrSub; } else { $lngCount = count($arrParent[5])+1; for($j=1;$i<=$lngCount-1;$j++) { $arrSubArray[$j] = $arrParent[5][$j]; } $arrSubArray[$j] = $arrContent; } $arrParent[5] = $arrSubArray; return true; } else if (count($arrParent[5])>0) { for ($i=1;$i<=count($arrParent[5]);$i++) { $blnFindParent = FindParent($arrParent[5][$i],$arrContent); if ($blnFindParent == true) { break; } } } return false; } "Alvaro G. Vicario" <kAlvaroNOSPAMTHANKS@terra.es> wrote in message news:<lgh250l3cvcz.1dj1915u8asuj.dlg@40tude.net>.. . > *** Aldo escribió/wrote (11 Oct 2004 10:16:16 -0700): > > i'm trying to translate this asp code to php, but i can't get it work right. > > could anyone help me? > > Maybe if you could shorten the question... Nobody's going to check six > hundred lines of code for you. |