10月112014
php 去掉 style 、 height 、width 属性
发布:2014-10-11 10:08 Saturday 分类:Php
阅读:5460次 评论:0条
有的程序会莫名奇妙的加上一下东西使得我们的内容在显示时候 会错位什么的 那么要用 php 去掉 style 、 height 、width 这么几个属性呢 我提供一下 网上看到的方法
这个是去掉 style 属性的代码
<?php
$html = '<IMG style="BORDER-BOTTOM: #c0c0c0 1px solid; " border=1 src="/10594713.jpg">';
$res = preg_replace('/style=".*?"/i', '', $html);
echo $res;
?>
这个是去掉 height 和 width 属性的代码
<?php$str='<img height=600 src="1296146383097_000.jpg" width=570 border=0 />';
$exp=Array("/height=.{0,5}\s/i","/width=.{0,5}\s/i");
$exp_o=Array('','');
echo preg_replace($exp,$exp_o,$str);
?>
本文固定链接: http://alzhai.com/post-551.html