在 PHP 中使用换行符分解数据库内容不会创建数组

发布于 2024-10-28 23:50:22 字数 147 浏览 5 评论 0原文

我在数据库中存储了一些带有换行符的值。

想要将这些内容转换为数组,我这样做了:

$arr = explode($rs[data],"\n");

不幸的是,这不起作用。关于出了什么问题有什么想法吗?

I've stored some values in my database which have linebreaks.

Wanting to transform those contents into an array, I did it like this:

$arr = explode($rs[data],"\n");

Unfortunately this doesn't work. Any ideas as to what's wrong?

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

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

发布评论

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

评论(2

怎言笑 2024-11-04 23:50:23

explode() 调用的参数是inverted :

  • 第一个参数应该是分隔符——它将用于分解字符串
  • ,第二个参数应该是字符串——它将被分解。

所以,你应该使用:

$arr = explode("\n", $rs[data]);

The parameters of your explode() call are inverted :

  • The first parameter should be the delimiter -- which will be used to explode the string
  • And the second parameter should be the string -- which will be exploded.

So, you should use :

$arr = explode("\n", $rs[data]);
只为一人 2024-11-04 23:50:23
$arr = explode("\n",$rs[data]);

您传递的参数错误,请尝试上面的操作

$arr = explode("\n",$rs[data]);

You are passing parameters wrongly try above

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