matrix);$i++) {
if ($this->matrix[$i]["parentTag"]==$parentTag) {
$out.= "{$i}:";
if ($this->matrix[$i]["tag"]!="") {
if ($this->matrix[$i]["pre"]!="") $out.=htmlspecialchars($this->matrix[$i]["pre"])."
";
$out.="".htmlspecialchars($this->matrix[$i]["tag"])."
{$i} ".$this->matrix[$i]["tagType"]."";
$out.=htmlspecialchars($this->matrix[$i]["post"]);
} else {
if ($this->matrix[$i]["pre"]!="") $out.=htmlspecialchars($this->matrix[$i]["pre"])."
";
$out.=htmlspecialchars($this->matrix[$i]["post"]);
}
if ($this->matrix[$i]["tag"]!="") {
$out.="
".$this->findSonsOfDisplayCode($i)."
\n";
if ($this->matrix[$i]["tagType"]!="") {
if (($this->matrix[$i]["tagType"]!="br") && ($this->matrix[$i]["tagType"]!="img") && ($this->matrix[$i]["tagType"]!="hr")&& ($this->matrix[$i]["tagType"]!="input"))
$out.="
".htmlspecialchars("". $this->matrix[$i]["tagType"].">")."{$i} ".$this->matrix[$i]["tagType"]."
";
}
}
$out.="
\n";
}
}
return $out;
}
private function removeSpacesAndBadTags($s) {
$i=0;
while ($i<10) {
$i++;
$s = preg_replace (
array(
'/[\r\n]/i',
'/ /i',
'/])*>( )*\s*<\/p>/i',
'/])*>( )*\s*<\/span>/i',
'/])*>( )*\s*<\/strong>/i',
'/])*>( )*\s*<\/em>/i',
'/])*>( )*\s*<\/font>/i',
'/])*>( )*\s*<\/small>/i',
'/<\?xml:namespace([^>])*><\/\?xml:namespace>/i',
'/<\?xml:namespace([^>])*\/>/i',
'/class=\"MsoNormal\"/i',
'/<\/o:p>/i',
'/])*>/i',
'//',
'/<\?(.|\s)*?\?>/'
),
array(
' ',
' ',
'',
'',
'',
'',
'',
'',
'',
'',
'',
' ',
'',
''
)
, trim($s));
}
return $s;
}
private function charByCharJob() {
$s = $this->removeSpacesAndBadTags($this->dirtyhtml);
if ($s=="") return;
$s = "".$s."";
$contenuto = "";
$ns = "";
$i=0;
$j=0;
$indexparentTag=0;
$padri=array();
array_push($padri,"0");
$this->matrix[$j]["tagType"]="";
$this->matrix[$j]["tag"]="";
$this->matrix[$j]["parentTag"]="0";
$this->matrix[$j]["pre"]="";
$this->matrix[$j]["post"]="";
$tags=array();
while($i" ){
// get chars till the end of a tag
$tag.=$s[$i];
$i++;
}
$tag.=$s[$i];
if($s[$i]==">") {
/*
$tag contains a tag <...chars...>
let's clean it!
*/
$tag = $this->fixTag($tag);
$tagType = $this->getTypeOfTag($tag);
$tag = $this->fixAutoclosingTags($tag,$tagType);
$tag = $this->mergeStyleAttributes($tag);
if (!isset($tags[$tagType])) $tags[$tagType]=0;
$tagok=true;
if (($tags[$tagType]==0)&&(stristr($tag,'/'.$tagType.'>'))) {
$tagok=false;
/* there is a close tag without any open tag, I delete it */
if ($this->debug) echo "Found a closing tag ".htmlspecialchars($tag)." at char $i without open tag: REMOVED
";
}
}
if ($tagok) {
$j++;
$this->matrix[$j]["pre"]="";
$this->matrix[$j]["post"]="";
$this->matrix[$j]["parentTag"]="";
$this->matrix[$j]["tag"]="";
$this->matrix[$j]["tagType"]="";
if (stristr($tag,'/'.$tagType.'>')) {
/*
it's the closing tag
*/
$ind = array_pop($padri);
$this->matrix[$j]["post"]=$contenuto;
$this->matrix[$j]["parentTag"]=$ind;
$tags[$tagType]--;
} else {
if (@preg_match("/".$tagType."\/>$/i",$tag)||preg_match("/\/>/i",$tag)) {
/*
it's a autoclosing tag
*/
$this->matrix[$j]["tagType"]=$tagType;
$this->matrix[$j]["tag"]=$tag;
$indexparentTag = array_pop($padri);
array_push($padri,$indexparentTag);
$this->matrix[$j]["parentTag"]=$indexparentTag;
$this->matrix[$j]["pre"]=$contenuto;
$this->matrix[$j]["post"]="";
} else {
/*
it's a open tag
*/
$tags[$tagType]++;
$this->matrix[$j]["tagType"]=$tagType;
$this->matrix[$j]["tag"]=$tag;
$indexparentTag = array_pop($padri);
array_push($padri,$indexparentTag);
array_push($padri,$j);
$this->matrix[$j]["parentTag"]=$indexparentTag;
$this->matrix[$j]["pre"]=$contenuto;
$this->matrix[$j]["post"]="";
}
}
}
} else {
/*
content of the tag
*/
$ns.=$s[$i];
}
$i++;
}
/*
remove not valid tags
*/
for ($eli=$j+1;$elimatrix);$eli++) {
$this->matrix[$eli]["pre"]="";
$this->matrix[$eli]["post"]="";
$this->matrix[$eli]["parentTag"]="";
$this->matrix[$eli]["tag"]="";
$this->matrix[$eli]["tagType"]="";
}
$errorsCounter = $this->checkTree(); // errorsCounter contains the number of removed tags
$this->fixedxhtml=$this->findSonsOf(0); // build html fixed
if ($this->debug) {
$this->fixedxhtmlDisplayCode=$this->findSonsOfDisplayCode(0);
echo "";
echo "| node id | ";
echo "pre | ";
echo "tag | ";
echo "post | ";
echo "parentTag | ";
echo "tipo |
";
for ($k=0;$k<=$j;$k++) {
echo "| $k | ";
echo " ".htmlspecialchars($this->matrix[$k]["pre"])." | ";
echo " ".htmlspecialchars($this->matrix[$k]["tag"])." | ";
echo " ".htmlspecialchars($this->matrix[$k]["post"])." | ";
echo " ".$this->matrix[$k]["parentTag"]." | ";
echo " ".$this->matrix[$k]["tagType"]." |
";
}
echo "
";
echo "
{$j}
\n\n\n\n".$this->fixedxhtmlDisplayCode;
}
return $errorsCounter;
}
}
?>