假设我有一个下面的字符串变量,其中包含此类字符串。
$sample_String = "Dummy User graded your comment \"\r\n\t\t\t\t\tdoc_ck.docx\r\n\t\t\t\t\tDownload\r\n\t\t\t\t\t\" that you posted.";
现在,我不希望这些HTML字符出现在我的字符串中。
如何有效,可靠地删除它们?我想要最终的输出字符串,如下所示:
$sample_String = "Dummy User graded your comment \"doc_ck.docx Download\" that you posted.";
当它在浏览器中'\'
显示时,“”之前的出现将消失,并且浏览器中的字符串如下所示:
虚拟用户对您发布的评论“ doc_ck.docx下载”进行了评分。
是不是
谢谢。
到现在为止,我尝试了以下代码,但没有成功:
function br2nl($buff = '') {
$buff = mb_convert_encoding($buff, 'HTML-ENTITIES', "UTF-8");
$buff = preg_replace('#<br[/\s]*>#si', "\n", $buff);
$buff = trim($buff);
return $buff;
}
$sample_String = br2nl(stripslashes(strip_tags($sample_String)));
如果您只想删除\r
(回车)\n
(换行符)和\t
(选项卡),则可以执行以下操作:
$string = "Dummy User graded your comment \"\r\n\t\t\t\t\tdoc_ck.docx\r\n\t\t\t\t\tDownload\r\n\t\t\t\t\t\" that you posted.";
$string = str_replace(array("\r", "\n", "\t"), "", $string);
如果要保留换行符(并使它们显示在浏览器中),请执行以下操作:
$string = "Dummy User graded your comment \"\r\n\t\t\t\t\tdoc_ck.docx\r\n\t\t\t\t\tDownload\r\n\t\t\t\t\t\" that you posted.";
$string = nl2br(str_replace(array("\r", "\t"), "", $string));
HTMLentity是类似"
和的序列?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句