能用PHP 去掉所有html标签里的部分属性吗?只要保留<a>标签里的超链接即可!
比如:<divid="m"><pid="lg"><imgsrc="../img/baidu_sylogo1.gif"width="27px"height="12px"us...
比如:
<div id="m"><p id="lg"><img src="../img/baidu_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>
去除后只剩下:
<div><p><img><map><a href="../yuanso/index.html"></map></p><p><a href="../yuanso/index1.html">文字1</a> <b>文字2</b> <a href="../yuanso/index3.html">文字3</a></p></div>
嗯解决了,还是自已研究的好,现在把代码贴出来与大家分享(不像有些人测都没测试,就贴出来;还说浪费自已时间呢;那我问你于吗要浪费时间发这贴呢,好笑,太好笑了,哈哈!!!!!!!!!!!1)!
<?php
$file='<div id="m"><p id="lg"><img src="../img/baidu_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;
?> 展开
<div id="m"><p id="lg"><img src="../img/baidu_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>
去除后只剩下:
<div><p><img><map><a href="../yuanso/index.html"></map></p><p><a href="../yuanso/index1.html">文字1</a> <b>文字2</b> <a href="../yuanso/index3.html">文字3</a></p></div>
嗯解决了,还是自已研究的好,现在把代码贴出来与大家分享(不像有些人测都没测试,就贴出来;还说浪费自已时间呢;那我问你于吗要浪费时间发这贴呢,好笑,太好笑了,哈哈!!!!!!!!!!!1)!
<?php
$file='<div id="m"><p id="lg"><img src="../img/baidu_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;
?> 展开
4个回答
展开全部
<?php
$file='<div id="m"><p id="lg"><img src="../img/baidu_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;
?>
$file='<div id="m"><p id="lg"><img src="../img/baidu_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;
?>
展开全部
//注释掉你想保存的
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;
}
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;
}
更多追问追答
追问
不行呵,你乱写吧?
追答
跟你这样的有什么好说的?真浪费我时间
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上已经回答得很清楚了
追问
你测试了吗,你不会也是想来拿分的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
任务飘过
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询