Php 存储多维数组中的特定值
这是我的阵列:Php 存储多维数组中的特定值,php,mysql,multidimensional-array,foreach,Php,Mysql,Multidimensional Array,Foreach,这是我的阵列: Array ( [0] => Array ( [0] => Received: from mout.perfora.net ([74.208.4.194]:64110) [1] => Received: from localhost (cpe-142-255-38-220.nyc.res.rr.com [142.255.38.220]) [2] => From:
Array
(
[0] => Array
(
[0] => Received: from mout.perfora.net ([74.208.4.194]:64110)
[1] => Received: from localhost (cpe-142-255-38-220.nyc.res.rr.com [142.255.38.220])
[2] => From: xxxxx <phoneleash@gearandroid.com>
[3] => To: 1v5z9hrt5z@thegrouptextshow.com
[4] => Message-ID: <1113754192.698.1364695577947.JavaMail.javamailuser@localhost>
[5] => References: <M38aa3cba44b8.+@gearandroid.com>
[6] => Subject: Re: SMS: +
[7] => MIME-Version: 1.0
[8] => Content-Type: multipart/mixed;
[9] => X-PhoneLeash: <M38aa3cba44b8.+@gearandroid.com>
[10] => Date: Sat, 30 Mar 2013 22:06:17 -0400
[11] => X-Provags-ID: V02:K0:leU7uup/etOXU8iaKYpIvO81rtv82ALEDU7D1ZsEeqw
[12] => Content-Type: multipart/alternative;
[13] => Content-Type: text/plain; charset=UTF-8
[14] => Content-Transfer-Encoding: 7bit
[15] => [Sent: 10:06 PM 03/30/2013]
[16] => Content-Type: text/html; charset=UTF-8
[17] => Content-Transfer-Encoding: 7bit
[18] => <HTML><HEAD></HEAD><BODY style="background-color:#ffffff">C TN<br>---<br>Add // to the end of your reply<br>[Sent: 10:06 PM 03/30/2013]<hr><table style="margin: auto;"><tr><td><a href=https://www.facebook.com/share.php?u=http://www.facebook.com/phoneleash><img src="http://gearandroid.com/pics/fbshare.png"></a></td><font face="helvetica"><td><a href=https://www.facebook.com/share.php?u=http://www.facebook.com/phoneleash>Enjoy PhoneLeash? Let your FB friends know!</a></td></font></tr></table><br></BODY></HTML>
)
[1] => Array
(
[0] => Received
[1] => Received
[2] => From
[3] => To
[4] => Message-ID
[5] => References
[6] => Subject: Re: SMS
[7] => MIME-Version
[8] => Content-Type
[9] => X-PhoneLeash
[10] => Date
[11] => X-Provags-ID
[12] => Content-Type
[13] => Content-Type
[14] => Content-Transfer-Encoding
[15] => [Sent
[16] => Content-Type
[17] => Content-Transfer-Encoding
[18] => <HTML><HEAD></HEAD><BODY style="background-color:#ffffff">C TN<br>---<br>Add // to the end of your reply<br>[Sent: 10:06 PM 03/30/2013]<hr><table style="margin
)
[2] => Array
(
[0] => from mout.perfora.net ([74.208.4.194]:64110)
[1] => from localhost (cpe-142-255-38-220.nyc.res.rr.com [142.255.38.220])
[2] => xxx <phoneleash@gearandroid.com>
[3] => 1v5z9hrt5z@thegrouptextshow.com
[4] => <1113754192.698.1364695577947.JavaMail.javamailuser@localhost>
[5] => <M38aa3cba44b8.+@gearandroid.com>
[6] => xxxxxxx
[7] => 1.0
[8] => multipart/mixed;
[9] => <M38aa3cba44b8.xxxxx@gearandroid.com>
[10] => Sat, 30 Mar 2013 22:06:17 -0400
[11] => V02:K0:leU7uup/etOXU8iaKYpIvO81rtv82ALEDU7D1ZsEeqw
[12] => multipart/alternative;
[13] => text/plain; charset=UTF-8
[14] => 7bit
[15] => 10:06 PM 03/30/2013]
[16] => text/html; charset=UTF-8
[17] => 7bit
[18] => auto;"><tr><td><a href=https://www.facebook.com/share.php?u=http://www.facebook.com/phoneleash><img src="http://gearandroid.com/pics/fbshare.png"></a></td><font face="helvetica"><td><a href=https://www.facebook.com/share.php?u=http://www.facebook.com/phoneleash>Enjoy PhoneLeash? Let your FB friends know!</a></td></font></tr></table><br></BODY></HTML>
)
)
数组
(
[0]=>阵列
(
[0]=>收到:来自mout.performa.net([74.208.4.194]:64110)
[1] =>收到:来自本地主机(cpe-142-255-38-220.nyc.res.rr.com[142.255.38.220])
[2] =>发件人:xxxxx
[3] =>至:1v5z9hrt5z@thegrouptextshow.com
[4] =>消息ID:
[5] =>参考资料:
[6] =>主题:回复:短信:+
[7] =>MIME版本:1.0
[8] =>内容类型:多部分/混合;
[9] =>X-PhoneLeash:
[10] =>日期:2013年3月30日星期六22:06:17-0400
[11] =>X-Provags-ID:V02:K0:leU7uup/etOXU8iaKYpIvO81rtv82ALEDU7D1ZsEeqw
[12] =>内容类型:多部分/可选;
[13] =>内容类型:文本/普通;字符集=UTF-8
[14] =>内容传输编码:7bit
[15] =>[发送时间:2013年3月30日晚上10:06]
[16] =>内容类型:文本/html;字符集=UTF-8
[17] =>内容传输编码:7bit
[18] =>C TN
--
在您的回复末尾添加//
[发送时间:2013年3月30日晚上10:06]
)
[1] =>阵列
(
[0]=>已收到
[1] =>收到
[2] =>来自
[3] =>到
[4] =>消息ID
[5] =>参考资料
[6] =>主题:回复:短信
[7] =>MIME版本
[8] =>内容类型
[9] =>X-PhoneLeash
[10] =>日期
[11] =>X-Provags-ID
[12] =>内容类型
[13] =>内容类型
[14] =>内容传输编码
[15] =>[已发送]
[16] =>内容类型
[17] =>内容传输编码
[18] =>C TN
--
在您的回复末尾添加//
[发送时间:2013年3月30日晚上10:06]
)
)
我需要能够存储
[1][18]
,[2][2]
,[2][10]
,[2][21]的值
到特定的变量中,这样我以后可以剪切其中的所有内容,除了实际的文本,然后将其作为值存储在MYSQL中。这对我有所帮助,但我只需要我指定的4个元素的值。您是否尝试过这样存储它们,其中$your_array
是上面保存数组的变量的名称
$var1 = $your_array[1][18];
$var2 = $your_array[2][2];
$var3 = $your_array[2][10];
$var4 = $your_array[2][21];
请记住,在上面显示的数组中没有[2][21]值。这就成功了:
require '../connect.php';
$email = file_get_contents('php://stdin');
preg_match_all("/(.*):\s(.*)\n/i", $email, $matches);
$message = $matches[1][18];
$message = str_replace('<HTML><HEAD></HEAD><BODY style="background-color:#ffffff">', '',$message);
$message = explode('<',$message);
$message = $message[0];
$sender = $matches[2][2];
$sender = explode('<',$sender);
$sender_id = $sender[0];
mysql_query("INSERT INTO `post` (`text`,`sender`,`text_stamp`,`post_date`,`post_time`) VALUES ('" . mysql_real_escape_string($message) . "','" . mysql_real_escape_string($sender_id) . "','" . mysql_real_escape_string($textdate) . "','$postdate','$posttime')") or die(mysql_error() . "<--There was error processing the query");
require'../connect.php';
$email=文件\u获取\u内容('php://stdin');
preg_match_all(“/(.*):\s(.*)\n/i“,$email,$matches);
$message=$matches[1][18];
$message=str_replace(“”,,$message);
$message=explode('yes.$var1、$var2等最后充当指向数组及其元素的指针。因此,当我尝试将变量插入mysql数据库时,它将作为数组插入,因此存储为空白字段[2][21]只有当有人通过电子邮件发送附件时才会出现。@user2218297:根据上述代码和您发布的数据,$var1
等应该是数组中的实际值,而不是“指向数组的指针”。如果上述代码产生“数组”然后,您的数据的格式与您在问题中发布的格式不同。$email=file\u get\u contents('php://stdin“);preg_match_all(“/(.*):\s(.*)\n/i”,$email,$matches);这是我用来生成该数组的代码……我发布的数组称为“$matches”谢谢你的帮助,伙计,我仍然没有得到应有的价值。我已经找到了一个关于我正在做什么的教程,它有助于推动事情的进展。一旦我开始工作,我会回答这个问题。如果你想回来的话,我可能会在11点之前完成。谢谢你的帮助,你就是那个人。hi@user2218297,很高兴见到你最后,我要做的另一个评论是看PDO,使用预先准备好的语句和绑定查询,因为mysql_*函数现在已被弃用,可能会让您面临某些安全问题。