2014-04-25 11:39
浏览 156


I have a basic survey builder and if the user specifies that the question requires one answer from a list (dropdown) then each possible answer needs to be saved in database.

Therefore my view has has a textarea were the admin can input the available answers and separates them with line breaks. I need to pull that text (line by line) and save in array so that my model can create a row per item.

My only issue is how to separate each line and save as array. The view is actually a popup and the data is sent using Ajax therefore the easiest way is to send the entire value as one input to the controller and then separate it in PHP. I was wondering if Laravel has a function ready for this or if I should use standard PHP such as str_replace etc...

图片转代码服务由CSDN问答提供 功能建议

我有一个基本的调查构建器,如果用户指定问题需要列表中的一个答案(下拉列表),那么 每个可能的答案都需要保存在数据库中。

因此我的视图有一个文本区域,管理员可以输入可用的答案并用换行符分隔它们。 我需要拉动该文本(逐行)并保存在数组中,以便我的模型可以为每个项目创建一行。

我唯一的问题是如何分隔每一行并保存为数组 。 该视图实际上是一个弹出窗口,数据是使用Ajax发送的,因此最简单的方法是将整个值作为一个输入发送到控制器,然后在PHP中将其分开。 我想知道Laravel是否准备好了这个函数,或者我是否应该使用str_replace等标准PHP ...

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dskpywvki951583595 2014-04-25 12:04

    as simple as this:

    $lines = explode(PHP_EOL, $string);
    点赞 评论

相关推荐 更多相似问题