[英]PHP JSON Encode with nl2br
the following code I use to populate t able via AJAX - 以下我用于通过AJAX填充的代码-
$sql = "SELECT * FROM web_task_comments WHERE web_task_id = '$taskId'
ORDER BY log_date DESC";
$result = mysql_query($sql)or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while($obj = mysql_fetch_object($result)) {
$arr[] = $obj;
}
echo json_encode($arr);
}
There is a row in the DB that will need nl2br() and then pass that back to AJAX request. 数据库中有一行需要nl2br(),然后将其传递回AJAX请求。 How do I do this with my current setup?
如何使用当前设置执行此操作? Can you use MySQL to convert nl to br in the query?
您可以使用MySQL在查询中将nl转换为br吗?
Thanks Rory 谢谢罗里
您可以使用MySQL的REPLACE
功能将所有换行符和回车符\\n
和\\r\\n
替换为<br />
: http : //dev.mysql.com/doc/refman/5.1/de/replace.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.