能用PHP 去掉所有html标签里的部分属性吗?只要保留<a>标签里的超链接即...
发布网友
发布时间:2022-04-29 22:01
我来回答
共4个回答
热心网友
时间:2022-04-18 02:31
<?php
$file='<div id="m"><p id="lg"><img src="../img/_sylogo1.gif" width="27px" height="12px" usemap="#mp"><map name="mp"><a shape="rect" coords="40,25,230,95" href="../yuanso/index.html" target="_blank" title="点此进入空间" ></map></p><p id="nv"><a href="../yuanso/index1.html">文字1</a> <b>文字2</b> <a href="../yuanso/index3.html">文字3</a></p></div>
';
$del=array("/name=.+?['|\"]/i","/src=.+?['|\"]/i","/id=.+?['|\"]/i","/width=.+?['|\"]/i","/height=.+?['|\"]/i","/usemap=.+?['|\"]/i","/shape=.+?['|\"]/i","/coords=.+?['|\"]/i","/target=.+?['|\"]/i","/title=.+?['|\"]/i");
$file = preg_replace($del,"",$file);//去除style样式
$file = str_replace(" ","",$file);//去除所有空格
$file = str_replace("<ahref=","<a href=",$file);//还原空格
echo $file;
?>
热心网友
时间:2022-04-18 03:49
//注释掉你想保存的
function htmltype($content)
{
if(!empty($content))
{
$replaces = array("/<style.*?>.*<\/style>/i" => '',
/*"/<img.*?>/i" => '',*/
"/<font.*?>/i" => '',
"/<\/font>/i" => '',
"/<strong>/i" => '',
"/<\/strong>/i" => '',
"/<span.*?>/i" => '',
"/<\/span>/i" => '',
"/<div.*?>/i" => "<p>",
"/<\/div>/i" => "</p>",
"/<table.*?>/i" => '',
"/<\/table>/i" => '',
"/<tbody.*?>/i" => '',
"/<\/tbody>/i" => '',
"/<tr.*?>/i" => '<p>',
"/<\/tr>/i" => '</p>',
"/<td.*?>/i" => '',
"/<\/td>/i" => '',
"/<ul.*?>/i" => "<p>",
"/<\/ul>/i" => "</p>",
"/<li.*?>/i" => "<p>",
"/<\/li>/i" => "</p>",
"/<h[1-6]+.*?>/i" => "<p>",
"/<\/h[1-6]+?>/i" => "</p>",
"/<a.*?>/i" => '',
"/<\/a>/i" => '',
"/<br(.*)?>/i" => "</p></p>",
"/<b>/i" => '',
"/<\/b>/i" => '',
"/<script.*?>.*<\/script>/i" => '',
"/<iframe.*?>.*<\/iframe>/i" => '',
"/style=\".*?\"/i" => '',
"/style=\'.*?\'/i" => '',
"/ /i" => '',
"/<p.*?>/i" => '<p>',
"/[( )|( )]/u" => '',
"/[\r|\n]+/" => '',
"/<p>(<p>)+/i" => '<p>',
"/<\/p>(<\/p>)+/i" => '</p>',
"/(<p><\/p>)+/i" => '',
"/<p>/i" => '<p> ',
);
foreach($replaces as $k => $v)
$content = preg_replace($k,$v,$content);
}
return $content;
}
热心网友
时间:2022-04-18 05:24
楼上已经回答得很清楚了追问你测试了吗,你不会也是想来拿分的吧
热心网友
时间:2022-04-18 07:15
任务飘过