<?php
$str = '<div id="content" style=" width:100px">contents</div>';
$output = preg_replace('/<div[^>]*>/i' , '<div>' , $str);
echo htmlspecialchars($output);
?>
//============================================================
<?php
$ary_html = array(
'div' => '<div id="content" style=" width:100px"></div>'
,'span' => '<span id="s" style=" width:100px"></span>'
,'td' => '<td id="sd" style=" width:100px"></td>'
,'tr' => '<tr id="aaa" style=" width:100px"></tr>'
,'th' => '<th id="cc" style=" width:100px"></th>'
,'body' => '<body id="ddd" style=" width:100px"></body>'
,'body' => '<body id="dafa" style=" width:100px"></body>'
,'html' => '<html xmlns="http://www.w3.org/1999/xhtml
"></html>'
,'head' => '<head id="head"></head>'
,'title' => '<title al=\'asd\'>this is the content</title>'
);
$reg = '/(<\w+)[^<]+>/im';
foreach($ary_html as $key => $val){
$str = preg_replace($reg , "$1>" , $val);
echo "<li>$key : " , color( htmlspecialchars($val) , 'red') , ' => ' , color(htmlspecialchars($str) , 'green');
}
function color($html , $color){
return "<font color=$color>" . $html . '</font>';
}
?>