PHP刪除HTMl標籤的三種解決方法

2021-08-08 11:52:40 字數 1262 閱讀 3801

本篇文章是對php刪除html標籤的三種解決方法進行了詳細的分析介紹,需要的朋友參考下

方法1:

直接取出想要取出的標記

複製**

**如下:

<?php

//取出br標記

function strip($str)

?>

方法2.

php 中有個 strip_tags 函式可以方便地去除 html 標籤。

echo strip_tags(「helloworld」); // 去除 html、xml 以及 php 的標籤。

對於非標準的 html **也能正確的去除:

echo strip_tags(「\」>cftea」); //輸出 cftea

在php中可以使用strip_tags函式去除html標籤,看下面示例:

複製**

**如下:

<?php

$str = 『wwwdreamdu

.com';

echo(htmlspecialchars($str).」

」);

echo(strip_tags($str));

?>

方法3.

strtr() 函式轉換字串中特定的字元。

語法

strtr(string,from,to)

或者

strtr(string,array)

引數描述

string1

必需。規定要轉換的字串。

from

必需(除非使用陣列)。規定要改變的字元。

to必需(除非使用陣列)。規定要改變為的字元。

array

必需(除非使用 from 和 to)。乙個陣列,其中的鍵是原始字元,值是目標字元。

例子1:

複製**

**如下:

<?php

echo strtr("hilla warld","ia","eo");

?>

例子2:

複製**

**如下:

<?php

$arr = array("hello" => "hi", "world" => "earth");

echo strtr("hello world",$arr);

?>

PHP刪除HTMl標籤的三種解決方法

方法1 直接取出想要取出的標記 複製 如下 php 取出br標記 function strip str 方法2.pzwbuekeeafhp 中有個 strip tags 函式可以方便地去除 html 標籤。echo strip tags hello world 去除 html xml 以及 php ...

php解耦的三種境界

我們有三個類,db,filesystem,session 實際業務需求要組合操作這三個類.class db class filesystem class session 實際邏輯 class logic public function handle id id 11 client new logic...

PHP刪除目錄的三種方法

1 遞規法 利用遞迴一層一層地刪除 deletedir dir else closedir dp else 2 系統呼叫法 function del dir dir else 3 迴圈法 function deltree pathdir else 如果是檔案就直接刪除 if is dir pathd...