用实际的换行符代码替换\ n [英] replace \n with actual new line character code

查看:107
本文介绍了用实际的换行符代码替换\ n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从使用mysql_real_escape_string进行过清理的数据库中提取内容. 因此,换行符现在显示为"\ n". 问题在于,此内容在<内显示给用户. pre>标记,因此我无法用<替换\ n br/>.

I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the new line characters now appear as "\n". The issue is that this content is displayed to users inside a < pre > tag so I cannot replace \n with < br/> for instance.

我想我可以在将结果插入<之前将\ n替换为实际的utf8字符代码. pre>.

I suppose I could replace \n with the actual utf8 character code before inserting the result inside the < pre>.

somoneone可以在这里协助吗?由于安全政策的缘故,实际上不选择不使用mysql_real_escape_string.

Can somoneone assist here? Not using mysql_real_escape_string isn't really an option due to security policy.

谢谢.

推荐答案

echo '<pre>'.str_replace('\n', "\n", $string).'</pre>';

这篇关于用实际的换行符代码替换\ n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆