<?php


$myfile = fopen("mf.txt", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
    $pp= fgets($myfile); // . "<br>";
    $pieces = explode(",", $pp);
   // var_dump(  $pieces );
    echo QrStr($pieces). "<br>";;
  }
  fclose($myfile);


  function QrStr( $pieces ){

    $nm  =  explode(" ", trim($pieces[1]));
    $lastName  =  $nm[ count($nm) -1 ];
    $midName  = ""; // trim( $nm[ count($nm) -2 ] );

    return "INSERT INTO market_import(email,name,firstname,lastname,middlename, phone,promo)
    VALUES ('".trim($pieces[2])."','".trim($pieces[1])."','".$nm[0]."','".$lastName."','".$midName."','".trim($pieces[6])."','LIVE0IFE');";
  }