gpt4 book ai didi

php - htmlspecialchars 不允许换行?

转载 作者:行者123 更新时间:2023-12-04 03:06:03 27 4
gpt4 key购买 nike

我在 mysql 字段中有如下的外观,

 Hello there
world

当我使用这段代码格式化上面的内容时:

 echo htmlspecialchars($thestring) 

它输出这个,

 Hello there<br/><br/>world

我怎样才能让它做换行符?

我想继续使用 htmlspecialchars 来帮助处理其他 html 字符。

最佳答案

您需要调用 nl2br 将换行符转换为 html:

nl2br(htmlspecialchars($text))

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

关于php - htmlspecialchars 不允许换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12121880/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com