如何识别数据库列中的换行符

发布于 2024-12-20 06:18:00 字数 97 浏览 1 评论 0原文

我在数据库列中有以下信息 - 我如何查找换行符以便我可以将其分成一个数组?

Address1
Address2
Address3

I have the following info in a db column - how could I look for the newline so I can seperate this into an array?

Address1
Address2
Address3

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

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

发布评论

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

评论(3

凉栀 2024-12-27 06:18:00

你可以尝试使用: "explode()"

$arr =explode ("\n" , $the_db_column_field)

然后进入 $arr 你将得到单个 "address1","address2","地址3”等..

(来自php官方

you can try with: "explode()"

$arr = explode ("\n" , $the_db_column_field)

and then into $arr you'll have te single "address1","address2","address3" etc..

(via php official)

╰◇生如夏花灿烂 2024-12-27 06:18:00

是的,你可以使用

$arr = explode("\n",$string);

你得到的

$add1 = $arr[0];
$add2 = $arr[1];
$add3 = $arr[2];

yes you can use

$arr = explode("\n",$string);

you get

$add1 = $arr[0];
$add2 = $arr[1];
$add3 = $arr[2];
毁梦 2024-12-27 06:18:00

这不是对您问题的直接回答,而是关于使用非标准化数据的警告。

在大多数情况下,这是一种糟糕的数据存储方式。每个字段应该只存储一个数据实体。考虑添加另一个名为“地址”的表,您可以在其中为原始表中的每一行存储多个地址。

如果您继续使用当前的解决方案,您可能会遇到多个问题,例如:很难搜索具有特定地址的实体,如果地址同时从两个客户端更新,则会出现并发问题,并且无法存储en 地址包含换行符等。

This is not a direct answer to your question, but a warning about using non-normalised data.

This is, in most cases, a horrible way to store data. You should store only one data entity per field. Consider adding another table called "addresses" where you can store multiple addresses for each row in the original table.

If you go ahead with your current solution you may see multiple problems along the way, such as: hard to search for entities with a certain address, concurrency problems if the addresses are updated from two clients at the same time and similar, impossible to store en address containing newlines and so on.

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