<?php /* * This php program inserts the alphabets and anchor links into the faculty list. * Written by Mahmud F. (mf4@umbc.edu) on 7/7/2009 * * 1) Run the MailMerge, instructions at: * http://www.umbc.edu/gradbusiness/techdocuments/system/faculty/faculty_web_listing * and save a text file (faculty_list.txt) of the output with no insertion of new lines, * windows(default) / West European, End lines with CR/LF and upload it to this directory. * * 2) Run this page and copy and paste the source into faculty_output.php * * 3) Verify the faculty page: http://www.umbc.edu/gradschool/about/faculty.html */ $file_array = file("faculty_list05062010.txt"); // Change this to whatever you named the file from the $arr = array(); function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; $ini += strlen($start); $len = strpos($string,$end,$ini)-$ini; return substr($string,$ini,$len); } foreach ($file_array as $v) { $parsed = get_string_between($v, "<p>", "</p>"); array_push($arr,"<p>".$parsed."</p>"); } $all = ""; $all .= "<a name=\"A\"></a><h3>A</h3>"; for($i=0;$i<=count($arr);$i++) { //count($arr) if($arr[$i] != "") { $aFaculty = $arr[$i]; $aFaculty2 = $arr[$i-1]; $aLetter1 = $aFaculty[11]; $aLetter2 = $aFaculty2[11]; if ( strpos($aLetter1, "A") !== false ){ $all .= $aFaculty; $boolB = false; } if ( strpos($aLetter1, "B") !== false ){ if ($boolB == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolB = true; } $all .= $aFaculty; $boolC = false; } if ( strpos($aLetter1, "C") !== false ){ if ($boolC == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolC = true; } $all .= $aFaculty; $boolD = false; } if ( strpos($aLetter1, "D") !== false ){ if ($boolD == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolD = true; } $all .= $aFaculty; $boolE = false; } if ( strpos($aLetter1, "E") !== false ){ if ($boolE == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolE = true; } $all .= $aFaculty; $boolF = false; } if ( strpos($aLetter1, "F") !== false ){ if ($boolF == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolF = true; } $all .= $aFaculty; $boolG = false; } if ( strpos($aLetter1, "G") !== false ){ if ($boolG == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolG = true; } $all .= $aFaculty; $boolH = false; } if ( strpos($aLetter1, "H") !== false ){ if ($boolH == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolH = true; } $all .= $aFaculty; $boolI = false; } if ( strpos($aLetter1, "I") !== false ){ if ($boolI == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolI = true; } $all .= $aFaculty; $boolJ = false; } if ( strpos($aLetter1, "J") !== false ){ if ($boolJ == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolJ = true; } $all .= $aFaculty; $boolK = false; } if ( strpos($aLetter1, "K") !== false ){ if ($boolK == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolK = true; } $all .= $aFaculty; $boolL = false; } if ( strpos($aLetter1, "L") !== false ){ if ($boolL == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolL = true; } $all .= $aFaculty; $boolM = false; } if ( strpos($aLetter1, "M") !== false ){ if ($boolM == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolM = true; } $all .= $aFaculty; $boolN = false; } if ( strpos($aLetter1, "N") !== false ){ if ($boolN == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolN = true; } $all .= $aFaculty; $boolO = false; } if ( strpos($aLetter1, "O") !== false ){ if ($boolO == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolO = true; } $all .= $aFaculty; $boolP = false; } if ( strpos($aLetter1, "P") !== false ){ if ($boolP == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolP = true; } $all .= $aFaculty; $boolQ = false; } if ( strpos($aLetter1, "Q") !== false ){ if ($boolQ == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolQ = true; } $all .= $aFaculty; $boolR = false; } if ( strpos($aLetter1, "R") !== false ){ if ($boolR == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolR = true; } $all .= $aFaculty; $boolS = false; } if ( strpos($aLetter1, "S") !== false ){ if ($boolS == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolS = true; } $all .= $aFaculty; $boolT = false; } if ( strpos($aLetter1, "T") !== false ){ if ($boolT == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolT = true; } $all .= $aFaculty; $boolU = false; } if ( strpos($aLetter1, "U") !== false ){ if ($boolU == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolU = true; } $all .= $aFaculty; $boolV = false; } if ( strpos($aLetter1, "V") !== false ){ if ($boolV == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolV = true; } $all .= $aFaculty; $boolW = false; } if ( strpos($aLetter1, "W") !== false ){ if ($boolW == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolW = true; } $all .= $aFaculty; $boolX = false; } if ( strpos($aLetter1, "X") !== false ){ if ($boolX == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolX = true; } $all .= $aFaculty; $boolY = false; } if ( strpos($aLetter1, "Y") !== false ){ if ($boolY == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolY = true; } $all .= $aFaculty; } if ( strpos($aLetter1, "Z") !== false ){ if ($boolZ == false){ $all .= "<a href=\"#top\">back to top</a><br /><a name=\"$aLetter1\"></a><h3>$aLetter1</h3>"; $boolZ = true; } $all .= $aFaculty; } } } $all .= "<a href=\"#top\">back to top</a><br /><br />"; printf($all) ; ?>
Probably not the most efficient code but it works :D