将制表符分隔的文本从文本区域分解为准备插入语句的数组

发布于 2025-01-10 22:04:35 字数 494 浏览 2 评论 0原文

我创建了一个文本区域,以便用户可以插入与特定模块关联的类代码。用户将从 Excel 中复制并粘贴到 html 文本区域中。例如:

“在此处输入图像描述”"

当粘贴到文本区域时,上面的内容由制表符分隔。在 php 中,我如何将每一行转换为单独的数组?例如,谢谢,任何帮助将不胜感激。

array(1)
(
    [0] => "moduleA"
    [1] => "class1"
)
array(2)
(
    [0] => "moduleA"
    [1] => "class2"
)
array(3)
(
    [0] => "moduleA"
    [1] => "class3"
)

I've created a textarea so users can insert class codes associated to a particular module. The user will copy from excel and paste into a html textarea. for example:

enter image description here

When pasted in the textarea the above is separated by tabs. In php how would i convert each row into a seperate array? e.g. Thanks, any help would be appreciated.

array(1)
(
    [0] => "moduleA"
    [1] => "class1"
)
array(2)
(
    [0] => "moduleA"
    [1] => "class2"
)
array(3)
(
    [0] => "moduleA"
    [1] => "class3"
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽清风入怀 2025-01-17 22:04:35

根据我的经验,textarea 中的新行(默认情况下)是 \n。您可以对每一行使用 \n 进行内爆/爆炸(取决于您想要的)。例如 explode("\n", $data);

From my experiences, a new row in textarea (by default) is a \n. You can implode/explode (depends on what you want) with \n for every row. e.g explode("\n", $data);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文