Jump to content

text file


onthespot

Recommended Posts

$filename= "data.txt";
$filehandler = fopen($filename, 'r');
$filedata= fread($filehandler, filesize($filename));
fclose($filehandler);
$rows = explode("\n", $filedata);
$first = true;
foreach ($rows as $row) {
   $rowdata = explode('/\s+/', $row);
   if(!$first)
      $insertvalues .= ", ";
   $insertvalues .= "('" . $rodata[0] . "', '" . $rowdata[1] . "');
   $first = false;
}
mysql_query("INSERT into table(name, id) VALUES(" . $insertvalues . ")");

 

Link to comment
https://forums.phpfreaks.com/topic/167382-text-file/#findComment-882601
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.