當前位置:首頁 » 編程語言 » 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);
}

熱點內容
成興ca鎖密碼初始密碼是什麼 發布:2024-04-20 19:24:43 瀏覽:667
如何更准確的看手機配置 發布:2024-04-20 19:15:12 瀏覽:332
匯優的演算法 發布:2024-04-20 19:10:51 瀏覽:414
和平精英暗夜危機模式密碼是什麼 發布:2024-04-20 19:10:03 瀏覽:686
韓國泡泡安卓怎麼充值 發布:2024-04-20 18:56:27 瀏覽:295
電腦極速緩存怎麼打開 發布:2024-04-20 18:55:43 瀏覽:143
哈弗h9有哪些高科技配置 發布:2024-04-20 18:51:29 瀏覽:773
平板的數字密碼在哪裡設置 發布:2024-04-20 18:39:13 瀏覽:972
華為雲連接伺服器 發布:2024-04-20 18:34:35 瀏覽:109
c語言ini文件讀寫 發布:2024-04-20 18:34:30 瀏覽:691