Forum Moderators: coopster
$i=0;
$graduate = '/([A-Z]{2,4}\s(5[0-9][0-9]))/';
preg_match_all ($graduate,$data,$matches);
// echo count($matches[0]);
while($i<=count($matches[0])){
$startpos = strpos($data,$matches[0][$i])-25;
// echo $startpos."<br/>";
if (!stripos($data, "AP 5")) {
$beginning = "<course";
$ending = "</course>";
$beginning_pos = strpos($data, $beginning, $startpos);
$middle_pos = $beginning_pos + strlen($beginning)-7;
$ending_pos = strpos($data, $ending, $beginning_pos + 1)+9;
$data = substr_replace($data, "", $middle_pos, $ending_pos - $middle_pos);
// echo "i'm in";
}
$i++;
}
<courseinfo>
<course code="EN 005">
<![CDATA[
<div class="courseblock"> <p class="courseblocktitle"><strong>EN 005. Basic English. 3 Credits.</strong></p> <p class="courseblockdesc"> A review of the fundamentals of composition designed to raise the student's command of English to the college level. Required for those whose tests and records demonstrate weakness in diction, spelling, grammar, punctuation and organization. Offered fall semester only. Students assigned to EN 005 must successfully complete the course before enrolling in EN 101. This course will not meet any degree requirements and cannot be used as an elective.<br /> </p> </div>
]]>
</course>
<course code="EN 101">
<![CDATA[
<div class="courseblock"> <p class="courseblocktitle"><strong>EN 101. Composition and Literature I. 3 Credits.</strong></p> <p class="courseblockdesc"> EN 101 is devoted chiefly to the principles of written organization, exposition, argumentation, and research.<br /> </p> </div>
]]>
</course>
"XX(XX) 5##" where the X are uppercase letters min 2 but max 4 and the 5## are numbers that start with a 5 but the # can be anything from 0-9 (three numbers total).
stripos may also return a non-Boolean value which evaluates to FALSE
...and go backward 25 characters
may also return a non-Boolean value which evaluates to FALSE
// Remove XML Doctype
$findthese = array('<?xml version="1.0"?>','<courseinfo>','</courseinfo>');
$data = trim(str_replace($findthese,'',$data));
// Remove Graduate courses
$i=0;
$graduate = '/\<course\scode\=\"([A-Z]{2,4}\s5[0-9][0-9])\"\>/';
preg_match_all ($graduate,$data,$matches);
while($i<=count($matches[0])){
$startpos = strpos($data,$matches[0][$i]);
if ($startpos < 0) $startpos = 0;
if (!stripos($data, "AP 5")) {
$beginning = "<course";
$ending = "</course>";
$beginning_pos = strpos($data, $beginning, $startpos);
$middle_pos = $beginning_pos + strlen($beginning)-8;
$ending_pos = strpos($data, $ending, $beginning_pos + 1);
$data = substr_replace($data, "", $middle_pos, $ending_pos - $middle_pos);
}
$i++;
}
$target = '/<course\scode="([A-Z]{2,4})\s([0-5][0-9][0-9])">/';
$clean1 = preg_replace($target,'',$data);
$findthese = array('<![CDATA[',']]>','<course>','</course>');
$output = str_replace('</div>','<a href="#top" class="inlinebtt">back to top</a></div>',str_replace($findthese,'',$clean1));
$output = substr($output,0, strrpos($output,"div>")+4);
return $output;
fclose($fp);
unset($data);