php 批量替換html標籤

2021-05-25 04:57:02 字數 655 閱讀 7576

1.把html元素全部去掉,或者保留某幾個html標籤

<?php

$text = 'test paragraph.

other text';

echo strip_tags($text);

echo "/n";

// allow and echo strip_tags($text, '');

?>

結果為(去掉了注釋):

test paragraph. other text

test paragraph.

other text

2.相反,只去掉某乙個html標籤

<?php

function strip_only($str, $tags, $stripcontent = false)

foreach($tags as $tag)

return $str;

}$str = 'red text';

$tags = 'font';

$a = strip_only($str, $tags); // red text

$b = strip_only($str, $tags, true); // text

?>

html替換把多有標籤替換成p標籤

按要求把html標籤替換 function replace html html elseif in array matchs 3 no tag else html 去掉換行,空格 replace arr array html str replace replace arr,mytag html p標...

PHP 批量生成靜態html

本示例圍繞 cms 系統的靜態頁面方案出發,展示批量生成靜態 html 功能。注 本文程式只能在 windows 的 dos 或 linux 下執行 php 命令來執行。本示例主要有4個檔案 config.inc.php 配置檔案 db.class.php 資料庫 pdo 類 model.class...

PHP 批量生成靜態html

本示例主要有4個檔案 config.inc.php 配置檔案 db.class.php 資料庫 pdo 類 model.class.php pdo資料庫操作類 index.php 執行檔案 header content type text html charset utf 8 date defaul...