doucang2831 2015-06-19 23:18
浏览 32
已采纳

使用PHP格式化动态文本

I have text fields which are populated from a database, the text when entered by the user is punctuated correctly with full stops and carriage returns etc.

Using VB with an ordinary db request:

<%=(rsMyrecordset.Fields.Item("text").Value)%>

I would get this result:

Mary had a little Lamb. Its fleece was as white as snow.

even if the user entered a return after the full stop after the word Lamb.

Using this code:

<%= Replace(rsMyRecordset.Fields.Item("text").Value, VbCrLf, "<br>") %>

The text returned would be:

Mary had a little Lamb.
Its fleece was as white as snow.

How would I achieve the same result using PHP? Currently I have:

<?php echo $row_rsMyRecordset['text']; ?>

Many thanks

  • 写回答

1条回答 默认 最新

  • duanqinjiao5244 2015-06-19 23:26
    关注

    maybe you are looking for nl2br: http://php.net/manual/function.nl2br.php

    <?php echo nl2br($row_rsMyRecordset['text']); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元