当前位置:首页 » 编程语言 » php正则p

php正则p

发布时间: 2022-05-15 17:27:54

‘壹’ php正则替换p标签的空白

你这个好像就只有<p />标签里面有空白,用正则吧:
$str = '<p> 2131231231231</p><a><p> 2131231<b>2</b>31231</p></a>';

$str = preg_replace('/\s+/', '', $str);
echo $str;

你试试。

‘贰’ php正则表达式如何写

/^(?:(?!<p>)[\s\S])*<p>[\s\S]*<\/p>(?:(?!<\/p>)[\s\S])*$/i

‘叁’ php正则获取p标签的内容

<?php
$Str = '<div class="evaluate cg"><ul class="comments-list"><li><div class="vcard-32 fl"><a rel="nofollow" ><img src="http://wwc.taobaocdn.com/avatar/getAvatar.do?userId=738846102&width=40&height=40&type=sns" alt="liuqiaoli616"></a></div><div class="content"><p class="nick"><a rel="nofollow" class="orange" >liuqiaoli616</a></p><p class="comment">鞋很轻巧,款式颜色也不错,号码偏小,至少要选大一个号码,买了3双,37码的两双有一边脚面是歪的,客服不怎么样,便宜东西懒得计较了,晚上出去散步凑合穿,下次会换一家买</p></div></li><li><div class="vcard-32 fl"><a rel="nofollow" ><img src="http://a.tbcdn.cn/app/sns/img/default/avatar-40.png" alt="i***n"></a></div><div class="content"><p class="nick"><a rel="nofollow" class="orange" >i***n</a></p><p class="comment">鞋子口小,穿脱费力,来时包裹的盒子都烂了,还以为只是寄了袋子来,整个盒子就挤变形,塌掉了,东西还没收到就降价了,气味很大,鞋底很不舒服,穿一小会二就有烧脚心的感觉</p></div></li><li><div class="vcard-32 fl"><a rel="nofollow" ><img src="http://wwc.taobaocdn.com/avatar/getAvatar.do?userId=89217211&width=40&height=40&type=sns" alt="一叶红枫飘"></a></div><div class="content"><p class="nick"><a rel="nofollow" class="orange" >一叶红枫飘</a></p><p class="comment">很满意,第二次光顾了。鞋子很舒适,轻巧,就是味道有点重,不过吹吹就可以了。快递因为五一放假来得慢,可以理解的。卖家说的全五分就返现2元,我貌似没收到。</p></div></li></ul></div>';

preg_match_all('/<p[^>]*>([^<|>]*)</p>/is', $Str, $Html);

echo '<p>', join("</p> <p>", $Html[1]), '</p>';

结果:

‘肆’ PHP正则去掉<p>和</p>

$new = preg_replace("/<p.*?>|<\/p>/is","", $str);
var_mp($new);

‘伍’ php正则过滤掉<p></p>

<p>(<img([^>]*)/>)</p>
这样子就可以提出图片出来了

‘陆’ PHP如何正则匹配alt><p></p><img和</div><p></p><div>

1,过滤所有html标签的正则表达式:</?[^>]+>
2,过滤所有html标签的属性的正则表达式:$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);
3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):</?[^pP/>]+>
4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):</?[aApPbB][^>]*>
5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):\s(?!alt)[a-zA-Z]+=[^\s]*

‘柒’ 怎样用PHP正则替换特定标志及其间的字符呢

你的第一个需求,是可以满足的
第二个需求,程序无法满足,因为程序不是人,不可能识别到丢失的右中括号在哪里结束

以下是已经运行通过的代码

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
$str = "【喜讯】全国——乐享周六【8点到18点】 世【界杯纪念】足球【大】放送";
$str = check($str);
echo $str;
function check($str){
if(strstr($str,'【') && strstr($str,'】')){
$str = change($str);
$str = check($str);
return $str;
}else{
return $str;
}
}
function change($str){
preg_match('/【(.*?)】/',$str,$result);
$last = str_replace($result['0'],'',$str);
return $last;
}
?>

‘捌’ PHP正则获取整个页面<p>标签里面的内容

htmlspecialchars是将html转码,防止XSS攻击的。你这样没有意义。

CURL获取内容后直接preg_match_all('/<p>(.*?)</p>/');就可以了
还有不懂的可以追问

‘玖’ php正则将p标签替换成br

<?php
$pattern="#<p>#";
$string=preg_replace($pattern,"<br>",$string);

?>

‘拾’ php 如何用正则让编辑器中img添加一个p标签进行包裹并且居中显示

之前也有同样的需求,把项目代码给你吧。
// 返回小发猫文章的图片数据
function replace_img_tag($contents, &$img_arr) {
$count = preg_match_all('/(<img[^>]+>)/i', $contents, $matches);
$keys = array();
foreach ($matches[0] as $key => $value) {
# code...
$keys[] = ' 0x' . dechex($key+9500) . ' ';
}
$img_arr = $matches[0];
return str_replace($matches[0], $keys, $contents);
}

热点内容
优化算法pdf 发布:2024-05-03 14:18:10 浏览:291
python算法书 发布:2024-05-03 14:14:25 浏览:736
方舟怎么加入服务器闪退 发布:2024-05-03 14:05:27 浏览:491
安卓心跳怎么打出来 发布:2024-05-03 13:59:23 浏览:100
存储标准性 发布:2024-05-03 13:37:07 浏览:416
液碱存储 发布:2024-05-03 13:21:13 浏览:156
linux如何改配置文件 发布:2024-05-03 13:00:54 浏览:31
哪个安卓模拟器老爷机带得动 发布:2024-05-03 13:00:49 浏览:576
编程与实战 发布:2024-05-03 12:54:30 浏览:38
电脑开机有密码rpc服务器不可用 发布:2024-05-03 12:40:54 浏览:471