Home  >  Article  >  Backend Development  >  How to remove tag attributes in php

How to remove tag attributes in php

藏色散人
藏色散人Original
2021-12-13 09:28:451511browse

php method to remove tag attributes: 1. Create a PHP sample file; 2. Remove the tag attributes through "preg_replace($del,"",$file);" and other methods.

How to remove tag attributes in php

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

How to remove tag attributes in php?

Use PHP to remove some attributes in all html tags

".$dir."

"; $path2=''; while ($file = readdir($dp)) //遍历目录 { if ($file !='.'&&$file !='..') //如果文件不是当前目录及父目录 { $path=$dir."/".$file; //获取路径 if(is_dir($path)) //如果当前文件为目录 { view_dir($path); //递归调用 } else //如果不是目录 { //echo ''; $path2 .= $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 ''; //echo ''; //echo ''; //echo ''; //echo '
'.$path.' 复制至XX删除
'; } } } return $path2."\r\n"; closedir($dp); } $dir='E:book\chigb\x'; echo view_dir($dir); $file='

文字1 文字2 文字3

'; $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("PHP Video tutorial》

The above is the detailed content of How to remove tag attributes in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn