simple PHP to MYsql filtering

As I understand you receive plain text emails with data.

Then you want to parse it. If your ‘labels’ are automatically generated and consistent then you can parse it quite easily… say something like this:

Say you load your email text into a variable $email_content.

$lines = explode("\n",$email_content);
$array_of_values = array();
foreach ($lines as $line) {
    if (str_pos(":",$line)!==false) {
        $temp_array = explode(":",$line);
        $array_of_values[trim($temp_array[0])] = trim($temp_array[1]);
    }
}

In the end you will have an array like this:

array(
    'First Name'=> 'John',
    'Last name' => 'Smith',
    'telephone' => '01234 56789'
)

Then you will be able to easily access whichever value you like by key and subsequently save it to database if you like.

There are certain assumptions though – that you only have : in lines that contain label:value pairs. Also end of the line char is always /n. But this is just a pointer not a ready made solution.

Leave a Comment