您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“php如何去除標(biāo)簽的屬性”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
php去除標(biāo)簽屬性的方法:1、創(chuàng)建一個PHP示例文件;2、通過“preg_replace($del,"",$file);”等方法去除標(biāo)簽的屬性即可。
本文操作環(huán)境:Windows7系統(tǒng),PHP7.4版,Dell G3電腦。
php怎么去除標(biāo)簽的屬性?
用PHP 去掉所有html標(biāo)簽里的部分屬性
<?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 !='..') //如果文件不是當(dāng)前目錄及父目錄 { $path=$dir."/".$file; //獲取路徑 if(is_dir($path)) //如果當(dāng)前文件為目錄 { view_dir($path); //遞歸調(diào)用 } 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.'> 復(fù)制至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="點此進(jìn)入空間" ></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如何去除標(biāo)簽的屬性”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。