tag_array_count = 0; $this->tag_check_array_count = 0; $this->flg = true; $this->error_count = 0; $this->warning_count = 0; $this->line_count = 1; } function file_read_and_write($filename){ $contents = @file($filename); foreach($contents as $line){ $this->tag_line_check($line); $this->line_count++; } $this->checkRestOpenTag(); $this->line_count = 1; foreach($contents as $line){ print("".$this->line_count." ".htmlspecialchars($line,ENT_QUOTES)."
\n"); $this->line_count++; } } function control_information(){ $c_tag = ""; for($i = 0;$i < $this->tag_array_count;$i++){ $tagset = $this->tag_array[$i]; if($tagset->getControl() == true){ if($tagset->getTagname() == "xml" || ($tagset->getTagname() == "-" && $c_tag == "xml")){ if($tagset->getAttribute() == "version"){ print("XMLのバージョンは".$tagset->getAttributeValue()."です
\n"); }else{ if($tagset->getAttribute() == "encoding"){ print("XMLの文字コードは".$tagset->getAttributeValue()."です
\n"); } } $c_tag = "xml"; }else{ if($tagset->getTagname() == "xml-stylesheet" || ($tagset->getTagname() == "-" && $c_tag == "xml-stylesheet")){ if($tagset->getAttribute() == "type"){ print("スタイルシートのファイル形式は".$tagset->getAttributeValue()."です
\n"); }else{ if($tagset->getAttribute() == "href"){ print("スタイルシートのパスは".$tagset->getAttributeValue()."です
\n"); } } $c_tag = "xml-stylesheet"; } } } } print("
\n"); } function correct_check(){ if($this->flg == true){ print("正常!

\n"); }else{ print("エラー ".$this->error_count." 個!
\n"); print("警告 ".$this->warning_count." 個!

\n"); } print("あなたの使用したタグ
\n"); for($i = 0;$i < $this->tag_array_count;$i++){ $tagset = $this->tag_array[$i]; if($tagset->getControl() == false){ if($tagset->getTagname() != "-"){ print("
\n"); print("タグ名: ".$tagset->getTagname()."\n"); }else{ print(" "); } if($tagset->getAttribute() != ""){ print(" (属性名: ".$tagset->getAttribute()."\n"); }else{ print(" 属性名: なし\n"); } if($tagset->getAttributeValue() != ""){ print(" 属性値: ".$tagset->getAttributeValue().")\n"); }else{ print(" 属性値: なし\n"); } } } print("

\n"); } function tag_line_check($line){ $state = 0; $tagname = ""; $attribute = ""; $attribute_value = ""; $double_mark_count = 0; $attribute_count = 0; $question_count = 0; for($i = 0;$i < mb_strlen($line) - 2;$i++){ $c = $this->getCharacter($line,$i); if($c == "<"){ if($state == 0){ $state = 1; $tagname = ""; $attribute_count = 0; $question_count = 0; }else{ $this->errMessage_Output("不正な文字です。 -> < この文字は無視されます。"); } }else{ if($c == "/"){ if($state <= 1){ if($state == 1){ if($tagname == ""){ $state = 2; }else{ $state = 3; } } }else{ if($state == 4 && $attribute == ""){ $state = 3; $attribute_value = ""; $double_mark_count = 0; }else{ if($state == 5){ $attribute_value = $attribute_value.$c; }else{ $this->errMessage_Output("不正な文字です。 -> / この文字は無視されます。"); } } } }else{ if($c == ">"){ if($state == 1){ $this->add_tag_to_array(new TagSet($tagname,"","")); }else{ if($state == 2){ $this->check_closetag($tagname); }else{ if($state == 3){ if($question_count == 0){ $this->add_tag_to_taglist_array(new TagSet($tagname,$attribute,$attribute_value)); }else{ if($question_count == 1){ $this->errMessage_Output("\"?\"がありません。"); } } }else{ if($state == 4){ if($attribute != ""){ $this->errMessage_Output("\"=\"がありません。"); } if($attribute_count == 0 || $attribute != ""){ if($attribute_count == 0){ $this->add_tag_to_array(new TagSet($tagname,$attribute,$attribute_value)); }else{ $this->add_tag_to_taglist_array(new TagSet("-",$attribute,$attribute_value)); } } }else{ if($state == 5){ if($attribute_value == ""){ $this->warningMessage_Output("属性値がありません。属性値がないものとして処理します。"); } if($double_mark_count == 1){ $this->errMessage_Output("\"で閉じてください。"); }else{ if($double_mark_count == 0){ if($attribute_value != ""){ $this->errMessage_Output("属性値は\"でくくってください。"); } } } $this->add_tag_to_array(new TagSet($tagname,$attribute,$attribute_value)); } } } } } $state = 0; }else{ if($c == " "){ if($state == 2 || $state == 3){ $this->errMessage_Output("不正な文字です。 -> ".$c." この文字は無視されます。"); }else{ if($state == 1 || $state == 6){ $state = 4; $attribute = ""; } } }else{ if($c == "="){ if(!($state == 0 || $state == 4)){ $this->errMessage_Output("不正な文字です。 -> ".$c." この文字は無視されます。"); }else{ if($state == 4 && $attribute == ""){ $this->errMessage_Output("不正な文字です。 -> ".$c." この文字は無視されます。"); }else{ if($state == 4){ $state = 5; $attribute_value = ""; $double_mark_count = 0; } } } }else{ if($c == "?"){ if($state == 1){ if($tagname == "" && $question_count == 0){ $question_count = $question_count + 1; }else{ $this->errMessage_Output("不正な文字です。 -> ".$c." この文字は無視されます。"); } }else{ if($state == 5){ $attribute_value = $attribute_value.$c; }else{ if($state == 6 || $state == 4 && $attribute == ""){ if($question_count == 1){ $question_count = $question_count + 1; $state = 3; }else{ $this->errMessage_Output("不正な文字です。 -> ".$c." この文字は無視されます。"); } } } } }else{ if($state == 1 || $state == 2){ $tagname = $tagname.$c; }else{ if($state == 3 || $state == 6){ $this->errMessage_Output("不正な文字です。 -> ".$c." この文字は無視されます。"); }else{ if($state == 4){ $attribute = $attribute.$c; }else{ if($state == 5){ if($c == "\""){ $double_mark_count = $double_mark_count + 1; if($double_mark_count == 2){ $state = 6; if($question_count == 0){ if($attribute_count == 0){ $this->add_tag_to_array(new TagSet($tagname,$attribute,$attribute_value)); }else{ $this->add_tag_to_taglist_array(new TagSet("-",$attribute,$attribute_value)); } }else{ if($attribute_count == 0){ $t_tagset = new TagSet($tagname,$attribute,$attribute_value); $t_tagset->setControl(true); $this->add_tag_to_taglist_array($t_tagset); }else{ $t_tagset = new TagSet("-",$attribute,$attribute_value); $t_tagset->setControl(true); $this->add_tag_to_taglist_array($t_tagset); } } $attribute_count = $attribute_count + 1; } }else{ $attribute_value = $attribute_value.$c; } } } } } } } } } } } } } function getCharacter($line,$n){ return substr($line,$n,1); } function add_tag_to_array($tagset){ $this->add_tag_to_taglist_array($tagset); $this->add_tag_to_check_array($tagset); } function add_tag_to_taglist_array($tagset){ $this->tag_array[$this->tag_array_count] = $tagset; $this->tag_array_count++; } function add_tag_to_check_array($tagset){ $this->tag_check_array[$this->tag_check_array_count] = $tagset; $this->tag_check_array_count++; } function check_closetag($tagname){ $tagset = $this->tag_check_array[$this->tag_check_array_count - 1]; if($tagset->getTagname() != $tagname){ $this->isTagExist($tagset->getTagname()); }else{ $this->tag_check_array_count--; } } function isTagExist($tagname){ $exist = false; for($i = $this->tag_check_array_count - 2;$i >= 0;$i--){ $tagset = $this->tag_check_array[$i]; if($tagset->getTagname() == $tagname){ for($j = $i + 1;$j < $this->tag_check_array_count;$j++){ $t_tagset = $this->tag_check_array[$j]; $this->errMessage_Output("対応する終了タグがありません -> <".$t_tagset->getTagname().">"); } $this->tag_check_array_count = $i; $exist = true; } } if($exist == false){ $this->errMessage_Output("対応する開始タグがありません -> <".$tagname.">"); } } function checkRestOpenTag(){ if($this->tag_check_array_count != 0){ for($i = 0;$i < $this->tag_check_array_count;$i++){ $tagset = $this->tag_check_array[$i]; $this->errMessage_Output("対応する終了タグがありません -> <".$tagset->getTagname().">"); } } } function errMessage_Output($message){ print(htmlspecialchars("行 ".$this->line_count." ".$message,ENT_QUOTES)."
\n"); $this->error_count++; $this->flg = false; } function warningMessage_Output($message){ print(htmlspecialchars($message,ENT_QUOTES)."
\n"); $this->warning_count++; $this->flg = false; } } ?>