By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Javascript to PHP

P: 1
I need to change this to PHP...the array must be in a text file that is read in and put into an array.




Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title>Undergraduate Courses</title>
  7. <link rel="stylesheet" type="text/css" href="mystyles.css"/>
  8. <script type="text/javascript">
  9.  
  10.  
  11.  
  12. var courseArray=new Array(); 
  13. courseArray[0]= new Array("ACC", "202", "Financial Accounting Information", "Fall08");
  14. courseArray[1]= new Array("CHEM", "126", "Chemistry and Society", "Fall08");
  15. courseArray[2]= new Array("GTW", "100", "Gateways I", "Fall08");
  16. courseArray[3]= new Array("ITM", "200", "Introduction to Computers-Lab", "Fall08");
  17. courseArray[4]= new Array("ITM", "200L", "Introduction to Computers-Lect", "Fall08");
  18. courseArray[5]= new Array("MAT", "260" ,"Calculus I" ,"Fall08");
  19. courseArray[6]= new Array("PSY", "200", "General Psychology", "Fall08");
  20. courseArray[7]= new Array("ENG", "101", "Composition and Rhetoric I (LC)", "Spring09");
  21. courseArray[8]= new Array("GIS", "101", "International Business", "Spring09");
  22. courseArray[9]= new Array("GTW", "102", "Gateways 2", "Spring09");
  23. courseArray[10]= new Array("ITM", "251", "Visual Basic", "Spring09");
  24. courseArray[11]= new Array("MAT", "261", "Calculus II", "Spring09");
  25. courseArray[12]= new Array("ENG", "102", "Composition and Rhetoric II", "Fall09");
  26. courseArray[13]= new Array("LAN", "110", "Basic American Sign Language I", "Fall09");
  27. courseArray[14]= new Array("MAT", "262", "Calculus III", "Fall09");
  28. courseArray[15]= new Array("MAT", "300", "Differential Equations", "Fall09");
  29. courseArray[16]=new Array("MUS", "110", "Piano Class I", "Fall09");
  30. courseArray[17]= new Array("LAN", "111", "Basic American Sign Language II", "Spring10");
  31. courseArray[18]=new Array("MAT", "299", "Intro to Higher Mathematics", "Spring10");
  32. courseArray[19]= new Array("MUS", "111", "Piano Class II", "Spring10");
  33. courseArray[20]= new Array("MUS", "191", "World Music", "Spring10");
  34. courseArray[21]= new Array("PHL", "202", "Ethics", "Spring10");
  35. courseArray[22]= new Array("BIO", "112", "Environmental Science", "Fall10");
  36. courseArray[23]= new Array("CRM", "101", "Introduction to Criminology", "Fall10");
  37. courseArray[24]= new Array("MAT", "301", "Discrete Mathematics", "Fall10");
  38. courseArray[25]= new Array("MAT", "410", "Complex Analysis", "Fall10");
  39. courseArray[26]= new Array("MUS", "192", "World Music Chorus/Drumming", "Fall10");
  40. courseArray[27]= new Array("ART", "101", "Form and Idea", "Spring11");
  41. courseArray[28]= new Array("MAT", "310", "Probability and Statistics", "Spring11");
  42. courseArray[29]= new Array("MAT", "499", "History of Mathematics", "Spring11");
  43. courseArray[30]= new Array("SOC", "100", "Intro to Sociology", "Spring11");
  44. courseArray[31]= new Array("DAN", "200", "Dance/World Cultures", "Fall11");
  45. courseArray[32]= new Array("DAN", "261", "Stretching and Relaxation", "Fall11");
  46. courseArray[33]= new Array("ITM", "360", "Advanced Application Development", "Fall11");
  47. courseArray[34]= new Array("JOU", "101", "Introduction to Journalism", "Fall11");
  48. courseArray[35]= new Array("MAT", "310", "Probability and Statistics", "Fall11");
  49.  
  50.  
  51. //displays the courses in a table format 
  52. function dosstable (array) 
  53. {
  54. document.writeln("<input type='button' value='back' onclick='window.location.reload()'>")
  55. document.writeln("<table border>");
  56. document.writeln( "<tr><th>Department</th><th>Number</th><th>Title</th><th>Semester</th></tr>");
  57. var row;
  58. for (row=0; row<array.length; ++row)
  59. {
  60. document.writeln("<tr>");
  61. var col;
  62. for (col = 0; col<array[row].length; ++col)
  63. {
  64. document.writeln("<td>" + array[row][col] + "</td>");
  65. }
  66. document.writeln("</tr>");
  67. }
  68. document.writeln("</table");
  69. return;
  70.  
  71. }
  72.  
  73. // gets the user's choice for semester (semester) and goes through courseArray to see if the semester in that course matches and then outputs the course(s) 
  74. function searchSemester(semester) 
  75. {
  76. var str = "<input type='button' value='back' onclick='window.location.reload()'>";
  77. str += "<table border><tr><th>Department</th><th>Number</th><th>Title</th><th>Semester</th></tr>";
  78. for(i=0; i<=courseArray.length-1;i++){
  79. if(document.getElementById('semester').value==courseArray[i][3]) //checks to see if semester is the same as the semester in that course 
  80. {
  81. str += "<tr>";
  82. for (var col = 0; col<courseArray[i].length; ++col)
  83. {
  84. str += "<td>" + courseArray[i][col] + "</td>";
  85. }
  86. str += "</tr>";
  87. }
  88.   }
  89.   document.writeln(str);
  90. }
  91.  
  92. //gets the user's choice for department (department) and goes through courseArray to see if the department in that chouce matches and then outputs the course(s) 
  93. function searchDepartment(department){
  94. var str = "<input type='button' value='back' onclick='window.location.reload()'>";
  95. str +=  "<table border><tr><th>Department</th><th>Number</th><th>Title</th><th>Semester</th></tr>";
  96. for(i=0; i<=courseArray.length-1;i++){
  97. if(document.getElementById('department').value==courseArray[i][0]) //checks to see if semester is the same as the semester in that course 
  98. {
  99. str += "<tr>";
  100. for (var col = 0; col<courseArray[i].length; ++col)
  101. {
  102. str += "<td>" + courseArray[i][col] + "</td>";
  103. }
  104. str += "</tr>";
  105. }
  106.   }
  107.   document.writeln(str); 
  108. }
  109.  
  110. </script>
  111. </head>
  112. <body>
  113.  
  114. <p> <br/> <br/> </p>
  115.  
  116.  
  117. <label>Search by Semester:</label> 
  118. <select name="semester" id="semester">
  119. <option value="Default">Select a Semester</option>
  120. <option value="Fall08">Fall 08'</option>
  121. <option value="Spring09">Spring 09'</option>
  122. <option value="Fall09">Fall 09'</option>
  123. <option value="Spring10">Spring 10'</option>
  124. <option value="Fall10">Fall 10'</option>
  125. <option value="Spring11">Spring 11'</option>
  126. <option value="Fall11">Fall 11'</option>
  127. </select>
  128. <input type="button" value="Search" onclick="searchSemester('semester');" />
  129. <p> <br/> </p>
  130.  
  131.  
  132.  
  133.  
  134. <label>Search by Department:</label>
  135. <select id="department" name="department">
  136. <option value="Default">Select a Department</option>
  137. <option value="ACC">Accounting</option>
  138. <option value="ART">Art</option>
  139. <option value="BIO">Biology</option>
  140. <option value="CHEM">Chemistry</option>
  141. <option value="CRM">Criminology</option>
  142. <option value="DAN">Dance</option>
  143. <option value="ENG">English</option>
  144. <option value="GIS">Global Issues</option>
  145. <option value="GTW">Gateways</option>
  146. <option value="ITM">Information Technology</option>
  147. <option value="JOU">Journalism</option>
  148. <option value="LAN">Language</option>
  149. <option value="MAT">Mathematics</option>
  150. <option value="MUS">Music</option>
  151. <option value="PHL">Philosophy</option>
  152. <option value="PSY">Psychology</option>
  153. <option value="SOC">Sociology</option>
  154. <input type="button" value="Search" onclick="searchDepartment('department')"/>
  155. </select>
  156. </div>
  157. <p> <br/> </p>
  158.  
  159. <input type="button" value="View All Courses" onclick= "dosstable(courseArray)"/> 
  160.  
  161. </body>
  162. </html>
Nov 20 '11 #1
Share this Question
Share on Google+
3 Replies


P: 43
Lot of manual work :)
Nov 20 '11 #2

omerbutt
100+
P: 638
yeah , go ahead do that, convert the whole of it, whos stopping :D
regards,
Omer Aslam
Nov 22 '11 #3

100+
P: 1,059
Simplest way to do that is open replace window in your editor

select case sensitive
Add new Array in search box
add array in replace and press search next
after finding next press replace button.

it seems lot of work but simple technical way you can replace it :)
Nov 22 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.