我正在尝试将 HTML 代码转换为纯文本作为段落,HTML 代码将由 CKEDITOR 组成。然后我使用 strip_tags()
和 html_entity_decode()
将字符串转换为普通段落。对于正常的句子,它工作得很好,但是当你的句子内容中某些符号是首字母缩略词,例如 '
时,它不会被转换。我不知道如何理解这个问题。这是一个例子:
*输入CKEDITOR:
This is a notification, but don't worry about this
*PHP:
$message = '<p>This is a notification, but don't worry about this.</p>';
$message = strip_tags($message);
$message = html_entity_decode($message);
$message = preg_replace("/&#?[a-z0-9]+; | \r|\n/i","",$message);
echo $message;
*输出:
This is a notification, but don't worry about this.
最佳答案
默认情况下,html_entity_decode
仅转换双引号,而不转换单引号。使用以下命令来转换两者:
$message = html_entity_decode($message, ENT_QUOTES);
https://www.php.net/manual/en/function.html-entity-decode.php
关于php - 将 html 代码转换为纯文本时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57847856/