hec*_*iov -1 html php format cakephp
我正在使用cakephp作为我的Web应用程序.我有一个数据库表,我存储了一些以纯文本保存的文字.我能做什么,我可以得到它自己格式化的文本我html标记?
例如,我在数据库上有一个文本,如:
blablablabalbalblablablablablablablablabalbalbla.
otherotherotherotherotherother.
helloworldhelloworldhelloworldhelloworld.
Run Code Online (Sandbox Code Playgroud)
但是,当我得到它时,它显示如下:
blablablabalbalblablablablablablablablabalbalbla.otherotherotherotherotherother.helloworldhelloworldhelloworldhelloworld.
Run Code Online (Sandbox Code Playgroud)
但是我希望它像这样进入html:
<p>blablablabalbalblablablablablablablablabalbalbla.</p>
<p>otherotherotherotherotherother.</p>
<p>helloworldhelloworldhelloworldhelloworld.</p>
Run Code Online (Sandbox Code Playgroud)
无论如何要做到这一点?
小智 5
如果您只想保留线制动器,可以将文本包装成<pre>标签
<pre>
blablablabalbalblablablablablablablablabalbalbla.
otherotherotherotherotherother.
helloworldhelloworldhelloworldhelloworld.
</pre>
Run Code Online (Sandbox Code Playgroud)
否则在换行符上使用php替换str_replace等函数.例如:
$in = '
blablablabalbalblablablablablablablablabalbalbla.
otherotherotherotherotherother.
helloworldhelloworldhelloworldhelloworld.';
$out = '<p>'
$out .= str_replace("\n\r" , '</p><p>', $in);
$out .= '</p>';
echo $out;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3636 次 |
| 最近记录: |