我有一个可以包含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个标记,并且波斯语字符必须仍然可读.
http://php.net/manual/en/function.htmlentities.php
<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1936 次 |
| 最近记录: |