php如何去除标签的属性

发布时间:2021-12-13 09:36:50 作者:iii
来源:亿速云 阅读:111

本篇内容介绍了“php如何去除标签的属性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

php去除标签属性的方法:1、创建一个PHP示例文件;2、通过“preg_replace($del,"",$file);”等方法去除标签的属性即可。

php如何去除标签的属性

本文操作环境:Windows7系统,PHP7.4版,Dell G3电脑。

php怎么去除标签的属性?

用PHP 去掉所有html标签里的部分属性

<?php
set_time_limit(0);
function view_dir($dir)
{
$dp=opendir($dir); //打开目录句柄
//echo "<br>".$dir."<br><br>"; 
$path3='';
while ($file = readdir($dp)) //遍历目录
{
   if ($file !='.'&&$file !='..') //如果文件不是当前目录及父目录
   {    
    $path=$dir."/".$file; //获取路径
    if(is_dir($path)) //如果当前文件为目录
    {
     view_dir($path);   //递归调用
    }
    else   //如果不是目录
    {
 
//echo '<tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0">';
 
   $path3 .= $path."\r\n";
   
   $c=file_get_contents($path);
//   $c = str_replace('http://4.28.99.196/chigb', "", $c);
//   $c1=array(' tppabs="/style/book.css" rel="stylesheet"',' tppabs="/chigb/up.gif"',' tppabs="/chigb/1pix.gif"',' tppabs="/chigb/left.gif"',' tppabs="/chigb/right.gif"');
//   $c2 = str_replace($c1, "", $c);
 
$del=array("/tppabs=.+?['|\"]/i");
$c2 = preg_replace($del,"",$c);
   $c2 = str_replace('" >', '">', $c2);
 
   file_put_contents($path,$c2);
//echo '<td width="52%" height="25"><a href="'.$path.'">'.$path.'</a></td>';
//echo '<td width="17%" align="center"><a href='.$_SERVER['SCRIPT_NAME'].'?cp='.$path.'> 复制至XX</a></td>';
//echo '<td width="31%" align="center"><b><a href='.$_SERVER['SCRIPT_NAME'].'?cmd=del&name='.$path.'>删除</a></b></td>';
//echo '</tr>';
//echo '</table></td></tr>';
    }
   }
}
return $path3."\r\n";
closedir($dp);
} 
$dir='E:book\chigb\x';
echo view_dir($dir);
 
 
 
 
 
$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;
 
 
?>

“php如何去除标签的属性”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 去除HTML里的标签
  2. php怎么去除html的标签

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:如何实现Nginx+tomcat负载均衡的会话保持

下一篇:Keepalived+Lvs+Nginx如何搭建Nginx高可用集群

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》