1

This is my array:

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 <[email protected]>
            [3] => To: [email protected]
            [4] => Message-ID: <1113754192.698.1364695577947.JavaMail.javamailuser@localhost>
            [5] => References: <[email protected]>
            [6] => Subject: Re: SMS: +
            [7] => MIME-Version: 1.0
            [8] => Content-Type: multipart/mixed; 
            [9] => X-PhoneLeash: <[email protected]>
            [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 <[email protected]>
            [3] => [email protected]
            [4] => <1113754192.698.1364695577947.JavaMail.javamailuser@localhost>
            [5] => <[email protected]>
            [6] => xxxxxxx
            [7] => 1.0
            [8] => multipart/mixed; 
            [9] => <[email protected]>
            [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>
        )

)

I need to be able to store the values of [1][18], [2][2], [2][10], [2][21] into specific variables so that I can later cut everything in them besides that actually text and then store it as a value in MYSQL. This sort of helped me but I need the values of only the 4 elements that I specified.

2 Answers 2

2

This did the trick:

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");
1
  • Hi @user2218297, great to see you got it working in the end. One further comment I would make is looking at PDO, using prepared statements and bound queries as the mysql_* functions are now deprecated and can open you up to certain security issues. Commented Apr 3, 2013 at 8:09
1

Have you tried storing them as so, where $your_array is the name of the variable holding your array above?

$var1 = $your_array[1][18];
$var2 = $your_array[2][2];
$var3 = $your_array[2][10];
$var4 = $your_array[2][21];

Bare in mind though that in the array you showed us above that there is no [2][21] value.

11
  • yes. $var1, $var2, etc. ends up acting as a pointer to the array and its element. Therefore when i try to insert the variable into the mysql DB, it inserts as ARRAY and therefore is stored as a blank field Commented Apr 2, 2013 at 22:44
  • the [2][21] only comes up when someones sends an attachment via email. Commented Apr 2, 2013 at 22:45
  • 1
    @user2218297: From the above code and the data you have posted $var1 etc. should be the actual values from the array, not "pointer[s] to the array". If the above code results in the word "Array" then your data is in a different format to what you have posted in the question.
    – MrWhite
    Commented Apr 2, 2013 at 23:36
  • $email = file_get_contents('php://stdin'); preg_match_all("/(.*):\s(.*)\n/i", $email, $matches); this is the code that I use to generate that array... That array that I posted is called "$matches" Commented Apr 2, 2013 at 23:39
  • 1
    thanks for your help man, im still not getting the value. i have found a tutorial on what I am doing though and it is helping moving things along. I will answer the question once I get this working. Ill get it done probably by 11 ish if you want to check back. You are the man though thanks for your help so far Commented Apr 3, 2013 at 0:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.