<?php
include 'phpQuery-onefile.php';
?>
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>DOM</title> 
</head>  
<body> 
<?php  
$html = '<div class="float_right image_list"><a href="#" onclick="reply(3);return false" onmouseover="hover(this,true,\'reply_icon\')" onmouseout="hover(this,false,\'reply_icon\')"><img src="/images/system/null.gif" class="reply_icon" />回復</a><a href="post.php?t=21678&p=1&action=del&floor=3" onclick="del_post(this,3);return false"><img src="/images/icon/edit_trash.png" class="size_16_2" />刪除</a><a href="#" onclick="lock_user(80587);return false"><img src="/images/icon/lock.png" class="size_16_2" />封禁</a><span id="FAVOURITE_80587"><a href="#" onclick="collect_post(80587);return false"><img src="/images/icon/favorites.png" class="size_16_2" />收藏</a></span></div><a href="
http://zh.arslanbar.net/" onclick="alert(\'Are you a pig?\');">首頁</a>';
$doc = phpQuery::newDocumentHTML($html);
foreach ($doc["a"] as $a) {
    $a = pq($a);
    echo $a->text() . " ";
    echo $a->attr("onclick") . " ";    
    $text = $a->text();
    if ($text == "封禁") {
         $a->text("封你媽");
    }    
    // Remove dangerous attributes on each link
    $a->removeAttr("onclick")->removeAttr("onmouseover")->removeAttr("onmouseout");
    if ($a->attr("href") == "#") {
        $a->attr("href", "index.php"); // do not allow href to be '#'
    }
    $a->attr("target", "_blank"); // force all links to be opened in a new window    
    // Take out the images inside links
    // <a><img />something<a> => <img/><a>something</a>
    $img = $a["img"]->remove();
    $a->before($img);
}
$doc["img"]->removeAttr("class");
$doc["div"]->removeAttr("class");
// remove <span> but keep its content
foreach ($doc["span"] as $span) {
    $span = pq($span);
    $span->after($span->html());
    $span->remove();
}
// change <div> to <p>
/*foreach ($doc["div"] as $div) {
    $div = pq($div);
    $div->after("<p>" . $div->html() . "</p>");
    $div->remove();
}*/
echo "<hr>";
$result = $doc->html();
echo htmlspecialchars($result); 
?> 
</body> 
</html>