\n"; $line = preg_replace("/\'/","\'",$line); $line = preg_replace("/\"/","\\\"",$line); // echo "line aft: ".$line."
\n"; } //...this is the parser code.... which is going to be implemented modularly function parseDocument($fileName, $mode, $vars_array) { $fcontents = file($fileName); // get the contents of the file.. $rsltString = ""; // Initialize this variable to empty.... while (list($line_num, $line) = each($fcontents)) { if ($mode == "js") { // this is a js file...treat differently // parse the lines to remove apostrophes.. $matchExp = preg_match("/\'/", $line, $result); if ($matchExp) { $line = preg_replace("/\'/","\\'", $line); } } // parse the line to remove carriage returns. $matchExp = preg_match("/(.*)(\r)/", $line, $result); if ($matchExp) { $line = preg_replace("/.*\r/", $result[1], $line); } // parse the line to remove newlines $matchExp = preg_match("/(.*)(\n)/", $line, $result); if ($matchExp) { $line = preg_replace("/.*\n/", $result[1], $line); } // parse the line to replace the tags.. $matchExp = preg_match_all("/\<\!\-\-\s*COMANCHE\:(\w+)\s*\-\-\>/",$line,$result); if ($matchExp) { for ($count=0;$count<(sizeOf($result[1]));$count++) { if ($mode == "post") { //the variables for the array are in the vars array $value = $vars_array[$result[1][$count]]; } else { $value = ${$result[1][$count]}; } // remove backslashes from $value and convert quotes into HTML special chars $value = htmlspecialchars(stripslashes($value),ENT_QUOTES); $line = preg_replace("/\<\!\-\-\s*COMANCHE\:".$result[1][$count]."\s*\-\-\>/",$value,$line); } echo $line; } else { echo $line; } } } ?>