"; $noForm = 1; }else{ $data = text_read(FILEPATH.urlencode($page)); if($index>=0 && $index < count($columns)){ $data[$index]['vote']++; $data[$index]['ip']=$_SERVER['REMOTE_ADDR']; } text_write(FILEPATH.urlencode($page),$data); $msg = "投票完了しました
ありがとうございます。
"; $noForm = 1; } } //データからリスト作成 if(!isset($data)){ $data = text_read(FILEPATH.urlencode($page)); } require("template.php"); //以下サブルーチン //テキストファイルをパースして、配列にして返す。 function text_read($filename){ if(file_exists($filename)){ return str2array(join("",file($filename))); }else{ return array(); } } //配列をテキストファイルにして書き込み。 function text_write($filename,$array){ $fh = fopen($filename, 'w'); flock($fh,LOCK_EX); fwrite($fh, array2str($array)); flock($fh,LOCK_UN); fclose($fh); //chmod($filename,0666); } function array2str($array,$nestedlevel=0){ $result = ""; if(is_array($array)){ foreach($array as $k => $v){ $result.="<".urlencode($k).">".array2str($v,$nestedlevel+1).""; } }else{ $result = urlencode($array); } return $result; } function str2array($str){ $result = array(); $source = ereg_replace("\r|\n|\ ","",$str); //$current = 0; $key = ""; $current = 0; $max = strlen($source); $finished = false; $loop = 0; $loopmax = 32000; while(!$finished){ $tag = ereg_replace("^<([^>]*)>.*","\\1",$source); //print htmlspecialchars($tag)."--\n"; if($tag!=$source){ //終了タグ取得 //$source = ereg_replace("<$tag>","",$source); $source = substr($source,strlen("<$tag>")); $endtagpos = strpos($source,""); if($endtagpos!=-1){ $value = substr($source,0,$endtagpos); //print "->".htmlspecialchars($value)."--\n"; if(ereg("^<",$value)){ $result[urldecode($tag)]=str2array($value); }else{ $result[urldecode($tag)]=urldecode($value); } $source = substr($source,$endtagpos+strlen("")); $loop++; if($loop > $loopmax){ $finished = true;} }else{ print "PARSE ERROR!!"; exit(); } }else{ $finished = true; } } return $result; } ?>