PHP替换HTML标记

Agh*_*gha 0 html php tags

我有一个可以包含HTML标签的文本.我希望能够以纯文本格式查看它,而浏览器不会像HTML代码查看器那样解析html标签.

例如:替换<div><span><</span><span>d</span><span>i</span><span></span>v<span>></span>.

文本也可能包含utf-8字符,如阿拉伯语或波斯语.并且还必须更换所有标签.

例如:

there is no html tags in this line.

the following line is in farsi:
??? ?? ??? ????? ??? ?? ???? ?????

<div>
    <label>
        This is a sample text.
    </label>
</div>
Run Code Online (Sandbox Code Playgroud)

必须在上面的代码中替换最后4个标记,并且波斯语字符必须仍然可读.

Jon*_*201 5

http://php.net/manual/en/function.htmlentities.php

<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>
Run Code Online (Sandbox Code Playgroud)