很多站长朋友们都不太清楚php过滤width,今天小编就来给大家整理php过滤width,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php正则过滤抽取table中的数据 2、 php 文章需要过滤掉img标签 3、 php mysql查询的时候怎么过滤掉html 4、 php 过滤body里的东西 5、 请问PHP里怎么用正则表达式替掉图片里的宽和高 6、 正则匹配style="width: 700px; height: 551px;" php正则过滤抽取table中的数据elseif($paytypes=="Alipay"){
$url="alipay_".$paytypes."/alipayto.php?product=".$products."total_fee=".$total_fee."body=".$names."out_trade_no=".$out_trade_nos;
Header("Location:$url");
exit;
}
php 文章需要过滤掉img标签PHP的preg_replace函数是 执行一个正则表达式的搜索和替换
语法
1:preg_replace (pattern ,replacement ,subject,limit,count )
参数
描述
pattern 正则表达式(字符串或字符串数组)
replacement 用于替换的字符串或字符串数组
subject 要进行搜索和替换的字符串或字符串数组。
limit 可选。每个模式在每个subject上进行替换的最大次数。默认是 -1(无限)。
cout 可选。完成的替换次数
示例:
<?php// 把heigth高度属性删除,并添加width="100%"
$str = '<div><p>12312321</p><img src="/data/upload/help/202303/13/19bdc43ae2ac0e89e5b4bbbcf38781ed.jpg" height="213" /><span>111</span><img src="/data/upload/help/202303/13/6f0f7409b67f285e391e296b51f3fe7d.jpg" /></div>';
$str = preg_replace("/height\=\"[0-9]+?\"/","",$str);
$str1 = preg_replace("/src=\"(.+?)\"/","src=\"$1\" width=\"100%\"",$str);
print_r($str1);
?>
php mysql查询的时候怎么过滤掉html你这个问题我之前做项目的时候也遇到过,你可以从数据入库时入手解决,具体做法就是你可在把数据存入到数据的时候用strip_tags()函数剥离HTML标签,这样你在查询的时候就不会遇到这种情况了,完全都是数据,如果存入数据库的数据必须要有HTML标记的话那入库的时候可以考虑用htmlspacialchars()函数,希望能够帮到你
php 过滤body里的东西<?php
//保留标签
function strip_word_html($text, $allowed_tags = '<b><i><sup><sub><em><strong><u><br>')
{
mb_regex_encoding('UTF-8');
$search = array('/lsquo;/u', '/rsquo;/u', '/ldquo;/u', '/rdquo;/u', '/mdash;/u');
$replace = array('\'', '\'', '"', '"', '-');
$text = preg_replace($search, $replace, $text);
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
if(mb_stripos($text, '/*') !== FALSE){
$text = mb_eregi_replace('#/\*.*?\*/#s', '', $text, 'm');
}
$text = preg_replace(array('/<([0-9]+)/'), array('< $1'), $text);
$text = strip_tags($text, $allowed_tags);
//$text = preg_replace(array('/^\s\s+/', '/\s\s+$/', '/\s\s+/u'), array('', '', ''), $text);
$search = array('#<(strong|b)[^>]*>(.*?)</(strong|b)>#isu', '#<(em|i)[^>]*>(.*?)</(em|i)>#isu', '#<u[^>]*>(.*?)</u>#isu');
$replace = array('<b>$2</b>', '<i>$2</i>', '<u>$1</u>');
$text = preg_replace($search, $replace, $text);
$num_matches = preg_match_all("/\<!--/u", $text, $matches);
if($num_matches){
$text = preg_replace('/\<!--(.)*--\>/isu', '', $text);
}
return $text;
}
//去掉属性
function clean_inside_tags($txt,$tags){
preg_match_all("/<([^>]+)>/i",$tags,$allTags,PREG_PATTERN_ORDER);
foreach ($allTags[1] as $tag){
$txt = preg_replace("/<".$tag."[^>]*>/i","<".$tag.">",$txt);
}
return $txt;
}
//用来过滤html
function trmhtml($text){
$rm = '<p><img><br>';
$text = str_replace("nbsp;","",$text);
$text = strip_word_html($text, $rm);
$cit = clean_inside_tags($text, '<p><img>');
$cit = str_replace("nbsp;","",$cit);
return $cit;
}
//使用
$str = '<div class="nav_ent"><p>sss</p>
<div class="nav_ent1_1"><a href="/"><img src="/data/upload/help/202303/13/1199ee2e126399e814883b8d8d579a5c.jpg" /></a></div>
<div class="nav_ent1"><a href="/news/"><img src="/data/upload/help/202303/13/5582a298a477bddf4c9f7a683a63d320.jpg" alt="新闻" border="0"></a></div>
<div class="nav_ent2"><table width="100%" class=43160 cellpadding="0" cellspacing="0"><tr><td valign=top><A href="/world/" target=_top>国际</A>nbsp;nbsp;<A href="/china/" target=_top>时政</A>nbsp;nbsp;<A href="/opinion/" target=_top>评论</A>nbsp;nbsp;<A href="/photo/" target=_blank>图片</A>nbsp; <A href="/world/paper.htm" target=_blank>外媒</A>nbsp; <A href="/news/live/" target=_top>直播</A>nbsp; <A href="/news/special.htm" target=_top>专题</A>nbsp; <A href="/news/update.htm" target=_blank>滚动</A></td></tr><tr><td align=right colspan=1></td></tr></table></div>
</div>
<div class="clearit"id="top" name="top"></div>
<div class="gotop"><a href="#top">nbsp;</a></div>
</div>';
echo trmhtml($str);
?>
试试吧,看是不是要这样的效果!
请问PHP里怎么用正则表达式替掉图片里的宽和高你在php输出的时候不去输出高宽不就好了,或者用js也行,给你一个jQuery的列子,$('p>img').removeAttr('width').removeAttr('height')
不过,如果没有什么特别的追求,不建议修改,因为如果img没有高宽的话需要浏览器在图片加载后通过二次渲染来重新确定图片尺寸,这会影响代码执行效率。比较正规的网站上的图片都是有尺寸的哦。
正则匹配style="width: 700px; height: 551px;"<?php
$aa='<a href="pp.html" style="width: 700px; height: 551px;" title="abc">sadfasdf
<div style="sdf">
sdfsdf
</div>
</a>';
$aa = preg_replace("/style[=\"\']+[^\"\']*[\"\']/i", "", $aa);
echo $aa;
?>
关于php过滤width的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php过滤width php过滤空格的详细内容...