drrvnbwle80177811 2012-06-20 15:15
浏览 42
已采纳

在textarea中的多行上显示PHP字符串,使用指定的字符将其拆分

I have options stored in the database in the following format -

option1:Option 1;option2:Option 2;option3:Option 3;option4:Option 4

Users are able to edit these options, so when they are in the <textarea> I'd like for them to be displayed on seperate lines.

option1:Option 1
option2:Option 2
option3:Option 3
option4:Option 4

I'm trying to do this by replacing the ';' character that seperates the options with a new line (str_replace(';', PHP_EOL, $poll['poll_options']) - have also tried " ")

Even though this appears to be working (echo '<pre>'; print_r($poll['poll_options']); echo '</pre>'; shows the options correcty on a new line), when I place the text in a <textarea> the options are only seperated be a space.

Edit - I've changed the code I used (now reflected in this post) to that suggested by @John Conde, and it now works in FF.

Any tips on how to resolve? Thanks.

  • 写回答

1条回答 默认 最新

  • dongyupen6269 2012-06-20 15:17
    关注

    Try:

    $new_text = str_replace(';', PHP_EOL, $poll['poll_options']);
    

    str_replace() is easier to work with then regular expressions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题