function parse($quizFileName) { $quizFile = fOpen($quizFileName, 'r'); if ($quizFile) { $this->parseStart(); while (($quizLine = fGets($quizFile, 4096)) !== false) { $this->parseLine($quizLine); } $this->parseEnd(); fClose($quizFile); } }
/** * My prompt func because realine is not default module */ public function ask($string, $length = 1024) { static $tty; if (!isset($tty)) { if (substr(PHP_OS, 0, 3) == "WIN") { $tty = fOpen("\\con", "rb"); } else { if (!($tty = fOpen("/dev/tty", "r"))) { $tty = fOpen("php://stdin", "r"); } } } echo $string; $result = trim(fGets($tty, $length)); return $result; }
function readFiles($a) { $fname = explode("/", $a); $fnameNums = count($fname); $fname = $fname[$fnameNums - 1]; if (strcmp($fname, "loaddir.php") == 0) { echo "<script>alert('不能编辑该文件!');location.href='loaddir.php';</script>"; } //$exts=substr($a,-3); $exts = explode(".", $a); $extsNums = count($exts); $exts = $exts[$extsNums - 1]; if ($exts == "php" || $exts == "asp" || $exts == "txt" || $exts == "html" || $exts == "aspx" || $exts == "jsp" || $exts == "htm") { $handle = @fOpen($a, "r"); if ($handle) { echo "<h3>修改文件:{$a}</h3>"; echo "<form action='loaddir.php?action=doedit&urlstr={$a}' method='post'><textarea style='width:99%;height:300px;margin-left:auto;margin-right:auto;' name='content'>"; while (!fEof($handle)) { //$buffer=fGets($handle); //echo ubb(mb_convert_variables(fGets($handle),"gb2312","gb2312,utf-8")); //echo ubb(mb_convert_encoding(fGets($handle),"gb2312","utf-8,gb2312")); echo ubb(mb_convert_encoding(fGets($handle), "utf-8", "auto")); //echo ubb(iconv("utf-8,gb2312","gb2312",fGets($handle))); //echo ubb(fGets($handle)); } fClose($handle); echo "</textarea><h3><input type='submit' value='修改' /></h3></form>"; } else { //echo "文件不存在或不可用"; echo "<script>alert('文件不存在或不可用');location.href='loaddir.php';</script>"; } } else { //echo "不能编辑该文件"; echo "<script>alert('不能编辑该文件');location.href='loaddir.php';</script>"; } }
if (!@array_key_exists('pb-csv-file', @$_SESSION['sudo_user']) || !is_file(@$_SESSION['sudo_user']['pb-csv-file'])) { $action = ''; } else { $rem_old_entries = (bool) @$_REQUEST['rem_old_entries']; $file = @$_SESSION['sudo_user']['pb-csv-file']; $fh = @fOpen($file, 'rb'); if (!$fh) { echo 'Could not read file.'; } else { if (@array_key_exists('sep', @$_REQUEST) && @array_key_exists('encl', @$_REQUEST) && @array_key_exists('enc', @$_REQUEST)) { $sep = @$_REQUEST['sep']; $encl = @$_REQUEST['encl']; $enc = @$_REQUEST['enc']; } else { # try to guess separator $line = @fGets($fh); @rewind($fh); $cnt = array(); $cnt['s'] = (int) preg_match_all('/;/', $line, $m); $cnt['c'] = (int) preg_match_all('/,/', $line, $m); $cnt['t'] = (int) preg_match_all('/\\t/', $line, $m); if ($cnt['t'] > max($cnt['s'], $cnt['c'])) { $sep = 't'; } elseif ($cnt['s'] > max($cnt['c'], $cnt['t'])) { $sep = 's'; } elseif ($cnt['c'] > max($cnt['s'], $cnt['t'])) { $sep = 'c'; } else { $sep = 't'; } unset($line);