php -
即使有 htmlspecialchars 功能也能正常工作
问题描述
<br>
嗨,即使有功能,有什么方法可以使工作htmlspecialchars
。我的问题是,当我在函数htmlspecialchars
中放置文本时,即使文本有新行,也没有新行。我的代码是这样的:
$text_val = "
this is a line
it is a new line
one more line
";
$final_text = str_replace("\n","<br>",$text_val);
$text = htmlspecialchars($final_text);
echo $text;
结果是这样的:
this is a line it is a new line one more line
但我希望它像第一个:
this is a line
it is a new line
one more line
谢谢你们。
解决方案
使用内置的 PHP 函数nl2br $final_text = nl2br($text_val);
推荐阅读
- odoo - How to show only those products on Website which have Quantity in Hand in Odoo 10?
- python - How to count Observation between two dates
- .net-core - EnableComHosting with Self-Contained deployment
- java - Is there a way to "override" a jaxrs resource?
- jitsi-meet - 如何关闭 converse-plugins/jitsimee
- android - 如何调试您不知道的 android 项目的源代码?
- python - 我想在python中使用正则表达式提取地址,我可以在其中使用lookbehind,以便获得前面的3-4个包含地址的字符串
- exception - 从 WSDL URL 导入 java 存根类时出现异常
- c++ - 将内存分配给 std::array 时出错
- unity3d - UnityWebRequest 在某些 url 响应中无法接收数据