parse_html($old_HTML_string) * * @package * @author MTCook * @copyright Copyright (c) 2005 * @access public **/ class makeup_html{ /** * makeup_html::parse_html() * * @param mixed $text * @return **/ function parse_html($text){ // alles zwischen <> klein schreiben $text = preg_replace("|<(.*)>|Ue","'<'. stripslashes(strtolower('$1')). '>'",$text); // font -> span $text = str_replace("", "",$text); // Zeilenumbrüche einfügen $text = str_replace("

", "

\r\n",$text); $text = str_replace("

", "

\r\n",$text); $text = str_replace("", "\r\n",$text); $text = str_replace("", "\r\n",$text); $text = str_replace("", "
\r\n",$text); $text = str_replace("
", "\r\n",$text); $text = str_replace("", "\r\n",$text); $text = str_replace("", "\r\n",$text); $text = str_replace("", "\r\n",$text); $text = str_replace("", "\r\n",$text); $text = str_replace("
", "
\r\n",$text); $text = str_replace("
", "
\r\n",$text); $text = str_replace("", "\r\n",$text); //Unterstrichen $text = preg_replace("|(.*?)|is","$1",$text); //Schriftgröße $text = $this->Attribute_to_Style($text,"span","size","font-size"); //Text Farbe $text = $this->Attribute_to_Style($text,"span","color","color"); //Schriftart $text = $this->Attribute_to_Style($text,"span","face","font-family"); //Bilder Rand $text = $this->Attribute_to_Style($text,"img","border","border"); //img alt $text = $this->Attribute_check($text,"img","alt"); // img align gegen float austauschen $text = $this->Attribute_to_Style($text,"img","align","float"); $text = $this->Attribute_to_Style($text,"img","vspace","margin-top-bottom"); $text = $this->Attribute_to_Style($text,"img","hspace","margin-left-right"); //div p table align gegen float austauschen $text = $this->Attribute_to_Style($text,"div|p|table","align","text-align"); //Leerzeichen entfernen zwischen " > $text = preg_replace("|\"( *?)>|is","\">",$text); //Leerzeichen entfernen zwischen " /> $text = preg_replace("|\"( *?)/( *?)>|is","\" />",$text); //Leerzeichen entfernen $text = $this->Attribute_space_clear($text,"name|id"); // löschen von $text = preg_replace("##is","",$text); return $text; } /** * löschen von überflüssigen Leerzeichen in dem angegebenen Attributen * makeup_html::Attribute_space_clear() * * @param mixed $String zu durchsuchender String * @param mixed $Tag in welchem Tag * @return **/ function Attribute_space_clear($String,$Tag){ preg_match_all("#(".$Tag.")=\"([-/.;\:\= 0-9\#a-z_]*?)\"#is",$String,$l); for ($i=0;$i#is",$String,$t); for($i=0;$i<=count($t['0']);$i++){ if (!preg_match("#<(.*?)".$Search_Attribut."(.*?)>#is",$t['0'][$i],$t2)){ $String = str_replace($t['0'][$i],"<".$Tag." ".$Search_Attribut."=\"\" ".$t['1'][$i].">",$String); } } return $String; } /** * makeup_html::Attribute_to_Style() * * @param mixed $String zu durchsuchender String * @param mixed $Tag in welchem Tag ersetzt werden soll * @param mixed $Search_Attribut zu ersetzendes Attribut * @param mixed $Replace_Attribut durch dieses Attribut ersetzen (muß in der style_Attribute() Function vorkommen) * @return string bearbeiteter String **/ function Attribute_to_Style($String,$Tag,$Search_Attribut,$Replace_Attribut){ preg_match_all("#<(".$Tag.")([-/.;\:\"\= 0-9\#a-z_]*?)".$Search_Attribut."=\"([-/.;\:\"\= 0-9\#a-z_]*?)\"([-/.;\:\"\= 0-9\#a-z_]*?)>#is",$String,$t); for($i = 0;$i<=count($t['0']);$i++){ $String = str_replace($t['0'][$i],"<".$t['1'][$i]." ".$this->style_Attribute($Replace_Attribut,$t['3'][$i],$t['2'][$i].$t['4'][$i])." >",$String); } return $String; } /** * makeup_html::style_Attribute() * * @param mixed $StyleAttri * @param mixed $StyleAttri_Wert * @param string $Attribute_Rest * @return **/ function style_Attribute($StyleAttri, $StyleAttri_Wert, $Attribute_Rest=""){ switch($StyleAttri){ case "color": $New_Style = "color: ".$StyleAttri_Wert."; "; break; case "font-family": $New_Style = "font-family: ".$StyleAttri_Wert."; "; break; case "border": if ($StyleAttri_Wert == "0"){ $StyleAttri_Wert = "none"; } $New_Style = "border: ".$StyleAttri_Wert."; "; break; case "margin-top-bottom": $New_Style = "margin-top: ".$StyleAttri_Wert."px; margin-bottom: ".$StyleAttri_Wert."px; "; break; case "margin-left-right": $New_Style = "margin-left: ".$StyleAttri_Wert."px; margin-right: ".$StyleAttri_Wert."px; "; break; case "font-size": $Gr = array("1" => "8", "2" => "10", "3" => "12", "4" => "14", "5" => "18", "6" => "24", "7" => "36"); $New_Style = "font-size: ".$Gr[$StyleAttri_Wert]."pt; "; break; case "text-align": $New_Style = "text-align: ".$StyleAttri_Wert."; "; break; case "float": if ($StyleAttri_Wert == "left" || $StyleAttri_Wert == "right"){ $New_Style = "float: ".$StyleAttri_Wert."; "; } break; } if ($Attribute_Rest != ""){ if(preg_match("#(.*)style=\"(.*?)\"(.*)#is",$Attribute_Rest,$t)){ $temp = explode(";",$t['2']); for ($i=0;$i < count($temp);$i++){ // vorhandene Styls wieder anfügen wenn nicht schon vorhanden if (!preg_match("#^$StyleAttri:$#is",trim($temp[$i])) && trim($temp[$i]) != ""){ $Style_Rest .= trim($temp[$i])."; "; } } }else{ $t['1'] = trim($Attribute_Rest); } } $New_Style = "style=\"".trim($New_Style.$Style_Rest)."\" ".$t['1'].$t['3']; return $New_Style; } } ?>