function replaceInnerText($haystack, $startNeedle, $endNeedle, $needle, $newneedle, $loopthru=0) { /* This function replaces text inside a specified block of text */ $pstr=$haystack; $pos=getInnerStrpos($haystack,$startNeedle, $endNeedle); if(is_numeric($pos[0]) && is_numeric($pos[1])){ if($loopthru){ $tstr=$haystack; $pstr=""; while(is_numeric($pos[0]) && is_numeric($pos[1])) { $istr=substr($tstr,$pos[0],$pos[1]); //echo "
$istr"; $istr=ereg_replace($needle,$newneedle,$istr); $pstr.=substr($tstr,0,$pos[0]).$istr; $tstr=substr($tstr,$pos[0]+$pos[1],strlen($tstr)); $pos=getInnerStrpos($tstr, $startNeedle, $endNeedle); } $pstr.=substr($tstr,0,strlen($tstr)); } else{ $pstr=substr($haystack,$pos[0],$pos[1]); $pstr=ereg_replace($needle,$newneedle,$pstr); $pstr=substr($haystack,0,$pos[0]).$pstr.substr($haystack,$pos[1]+$pos[0],strlen($haystack)); } } return $pstr; } function getInnerStrpos($haystack, $startNeedle, $endNeedle) { $pos1=strpos($haystack, $startNeedle); $startNeedleWidth=strlen($startNeedle); $tstr=substr($haystack,$pos1+$startNeedleWidth,strlen($haystack)); $pos2=strpos($tstr, $endNeedle); if(is_numeric($pos2))$pos2=$pos2+strlen($startNeedle)+strlen($endNeedle); $spos[0]=$pos1; $spos[1]=$pos2; return $spos; } function chopInnerText($haystack, $startNeedle, $endNeedle, $loopthru=1, $keepvars=0) { /* This function returns a specified string with the text removed between the specified start string and end string. $haystack is the string you want manipulating $startNeedle is the starting point to look for $endNeedle is the point at which text stops being deleted if $loopthru is true, loops through the text until no other $start_txt to $end_txt can be found $keepvars leaves the $startNeedle and $endNeedle variables in the text string */ $pstr=$haystack; $pos=getInnerStrpos($haystack, $startNeedle, $endNeedle); if(is_numeric($pos[0]) && is_numeric($pos[1])) { if($loopthru) { $tstr=$pstr; $pstr=""; while(is_numeric($pos[0]) && is_numeric($pos[1])) { if($keepvars) { $pstr.=substr($tstr,0,$pos[0]+strlen($startNeedle)); $tstr=substr($tstr,$pos[0]+$pos[1],strlen($tstr)); } else { $pstr.=substr($tstr,0,$pos[0]); $tstr=substr($tstr,$pos[0]+$pos[1],strlen($tstr)); } $pos=getInnerStrpos($tstr, $startNeedle, $endNeedle); } $pstr.=substr($tstr,0,strlen($tstr)+1); } else { if($keepvars) { $pstr=substr($haystack,0,$pos[0]+strlen($startNeedle)); $pstr.=substr($haystack,$pos[1]+$pos[0]-strlen($endNeedle),strlen($haystack)); } else { $pstr=substr($haystack,0,$pos[0]); $pstr.=substr($haystack,$pos[1]+$pos[0],strlen($haystack)); } } } return $pstr; } function fileContents($filename) { $file=fopen($filename, "r"); $dFF=""; while(!feof($file)) { $dFF .= fread($file, 4096); } return $dFF; } $ftext=fileContents("menu.xml"); $level=0; $ftext=ereg_replace("\r","",$ftext); $ftext=ereg_replace("\n","",$ftext); $ftext = chopInnerText($ftext, "", 1, 0); $ftext = chopInnerText($ftext, "", "?>", 1, 0); $xmlA=split("<",$ftext); $menucode=""; $endlevel=-1; for($a=1;$a