Buenas...
Tengo este codigo que recibe uan seri de parametro logicos para realizar una limpieza en html de acuerdo a lo seleccionado pero etngo un error que las entidades no me las convierte y me pone caracteres extranos
alguien con una sugerencia para este problema.
Código PHP:
<?php
$p=$_POST['code'];
$alt=$_POST['alt'];
$boder=$_POST['border'];
$display_block=$_POST['displayblock'];
$summary=$_POST['summary'];
$height=$_POST['height'];
$doctype=$_POST['doctype'];
$metas=$_POST['metatags'];
$html_tag=$_POST['html'];
$body=$_POST['body'];
$links=$_POST['links'];
$comment=$_POST['comment'];
$strong=$_POST['strong'];
$em=$_POST['em'];
$gif_link=$_POST['giflink'];
$target=$_POST['target'];
$bullet=$_POST['bullet'];
if($alt==true){
$p=addAttributeToTagNoHas('img','alt','',$p);
}
if($border==true){
$p=addAttributeToTagNoHas('img','border','0',$p);
}
if($display_block==true){
$p=addAttributeToTagNoHas("img","style","display:block;",$p);
}
if($summary==true){
$p=addAttributeToTagNoHas('table','summary','',$p);
}
if($height==true){
$p=revomeAttributeToTag('table','height',$p);
}
if($doctype==true){
$p= preg_replace("/<!DOCTYPE\s*[^>]*\s*>/i",'',$p);
}
if($metas==true){
$p= preg_replace("/<meta[^>]+(http\-equiv|name)=\"([^\"]*)\"[^>]" . "+content=\"([^\"]*)\"[^>]*>/i",'', $p);
}
if($html_tag==true){
$p= preg_replace("/<html\s*[^>]*\s*>/i",'<html>',$p);
$p= preg_replace("/<HTML\s*[^>]*\s*>/i",'<html>',$p);
}
if($body==true){
$p= preg_replace("/<body\s*[^>]*\s*>/i","<body bgcolor=\"#ffffff\">",$p);
$p= preg_replace("/<BODY\s*[^>]*\s*>/i","<body bgcolor=\"#ffffff\">",$p);
}
if($links==true){
$p= preg_replace("/<link\s*[^>]*\s*>/i",'',$p);
}
if($comment==true) {
$p=preg_replace("/<!--(.*?)-->/i", "", $p);
}
if ($strong==true){
$p=str_replace('<strong','<b',$p);
$p=str_replace('strong>','b>',$p);
}
if ($em==true){
$p=str_replace('em>','i>',$p);
$p=str_replace('<em','<i',$p);
}
if ($gif_link==true){
$p=str_replace('</body>',"[!--$#GIF_LINK$--]\n</body>",$p);
}
if ($target==true){
$p=addAttributeToTagNoHas('a','target','_blank',$p);
}
if ($bullet==true) {
$p=str_replace('•','•',$p);
}
function addAttributeToTagNoHas($tag,$attribute,$value,$html)
{
@$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$imgs = $xpath->evaluate("/html/body//".$tag);
for ($i = 0; $i < $imgs->length; $i++) {
$img = $imgs->item($i);
if ($img->hasAttribute($attribute) != true) {
$img->setAttribute($attribute, $value);
}
}
return $dom->saveHTML();
}
function revomeAttributeToTag($tag,$attribute,$html)
{
@$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$tags = $xpath->evaluate("/html/body//".$tag);
for ($i = 0; $i < $tags->length; $i++) {
$tag = $tags->item($i);
if ($tag->hasAttribute($attribute) == true) {
$tag->removeAttribute($attribute);
}
}
return $dom->saveHTML();
}
$p=str_replace('/>','>',$p);
$p=str_replace(''',"'",$p);
$p=str_replace('’',"'",$p);
$p=str_replace('′',"'",$p);
$p=str_replace(' ','',$p);
$p=str_replace('–','–',$p);
$p=str_replace('—','—',$p);
$p=str_replace('†','†',$p);
$p=str_replace('™','™',$p);
$p=str_replace(' ',' ',$p);
$p=str_replace('©','©',$p);
$p=str_replace('®','®',$p);
$p=str_replace('·','·',$p);
$p=str_replace('http:///','http://',$p);
$p=str_replace('"ttp://','http://',$p);
$p=str_replace(' "','"',$p);
echo $p;
?>