<?php ini_set('memory_limit', '1024M'); define("ROOT",realpath(__DIR__).DIRECTORY_SEPARATOR); $file = ROOT.'data.txt'; if(is_file($file)){ $csv = array_map('str_getcsv', file($file)); $arr = ''; if(is_array($csv)){ foreach($csv as $line){ $arr[] = array('guid'=>$line[0],'icon'=>$line[1]); } } $head = 'INSERT INTO `tab_icon` (`id`, `icon`) VALUES'; foreach($arr as $ln){ $head .= "('{$ln['guid']}','{$ln['icon']}'), \n"; } $head = substr($head, 0, -3).';'; file_put_contents(ROOT.'tab_icon.sql',$head); }?>
My code to which I read in-line file txt File contents:
1 weapon_small_sword_i00
2 weapon_long_sword_i00
3 weapon_broad_sword_i00
4 weapon_club_i00
5 weapon_mace_i00
etc.
Tell me how I can extract my data in this way - ( id
, icon
). In my case, everything is saved line by line in 1 column, and the second is empty