[Solved] PHP Read lines in blocks in a file


Try this its working

<?
$file = file("data.txt");
foreach($file as $key => $value)
{
$filter_value = trim($value);
if($filter_value!="" && $filter_value!="----SMS_START----" && $filter_value!="----SMS_END----"){
$new_array[] = $value;
$my_array = array_chunk($new_array, 7);
}
}
$count = count($my_array);
for($I=0;$I<$count;$I++){
foreach($my_array[$I] as $key => $value){
$ss = explode(":", $value);
$mm_array[$I][$ss[0]] = str_replace($ss[0].":", "", $value);
}
}


echo "<pre>";
print_r($mm_array);
echo "</pre>";
?>

The result

Array
(
[0] => Array
    (
        [recv_time] => 2014-10-09 18:32:39

        [Span] =>  1

        [From-Number] =>  +1347XXXXXXX

        [Timestamp] =>  14/10/09 18:32:16 96

        [Type] =>  PDU

        [SMS-SMSC-Number] =>  +12404492163

        [Content] =>  Thanks,

    )

[1] => Array
    (
        [recv_time] => 2014-10-09 18:35:00

        [Span] =>  1

        [From-Number] =>  +1347XXXXXXX

        [Timestamp] =>  14/10/09 18:34:37 96

        [Type] =>  PDU

        [SMS-SMSC-Number] =>  +12404492163

        [Content] =>  Thanks

    )

[2] => Array
    (
        [recv_time] => 2014-10-10 18:04:05

        [Span] =>  1

        [From-Number] =>  +28809090

        [Timestamp] =>  14/10/09 23:03:42 96

        [Type] =>  PDU

        [SMS-SMSC-Number] =>  +12404492163

        [Content] =>  AT&T Free Msg: If this was done in error, please call 611 or    800.901.9878.

    )

)

You can now easily inserted to the database

Enjoy!

1

solved PHP Read lines in blocks in a file