我正在使用我的 PHP 从 mysql 数据库中获取数据。当我将两个文件名都存储在数据库中时,使用值将文件名存储在数组中时遇到问题。这是我存储在 blob 中的内容:draft_attachment.rardraft_attachment - Copy.rar这是代码:$mailbox = $link->prepare("SELECT * FROM draft WHERE id = ?");$mailbox->execute([$id]);// set the resulting array to associative$row = $mailbox->fetch(PDO::FETCH_ASSOC);$attachments = array();if($mailbox->rowCount() == 1){ $attachment = array(); $draft_to = htmlspecialchars($row['to_email']); $draft_subject = quoted_printable_decode($row['subject']); $draft_message = $row['message']; $attach[] = $row['attachments'];}?>当我尝试这个时:$attach[] = $row['attachments'];它将两个字符串存储在数组中:Array{ [0] => draft_attachment.rardraft_attachment - Copy.rar}所以我试过这个:$attachments = array(); $i = 0;if($mailbox->rowCount() == 1) { $attachments[$i] = $row['attachments']; $i++;}它不会单独存储字符串,所以我不知道该怎么做。这是我想要实现的目标:Array{ [0] => draft_attachment.rar [1] => draft_attachment - Copy.rar}你能告诉我一个例子,我如何让两个字符串分开,这样我就可以使用该值将它们存储在数组中?谢谢你。
1 回答

手掌心
TA贡献1942条经验 获得超3个赞
preg_split
您可以使用on \R
(任何新行字符序列)拆分字符串(explode
如果您知道确切的行结束字符,也可以使用):
$attachments = preg_split('/\R/', $row['attachments']);
- 1 回答
- 0 关注
- 189 浏览
添加回答
举报
0/150
提交
取消