Miko Posted July 24, 2009 Share Posted July 24, 2009 hello, a friend of mine asked that I could create a php script which can import a text file with data content build up like this: FR|01220||S293|GCHRF,GEAFR,GEDOM||D041|0448|0|V25|37| FR|01220||S314|CBE,CES,CNL,CRU,GCHRF,GEAFR,GEDOM||D041|0448|7|V25|37| FR|01220||S882|||D041|0448|7|V25|37| FR|01220||S327328|||D016|1074|3|1|37| FR|01220||S299,S302303|CBE,CES,CNL,CRU,GCHRF,GEAFR,GEDOM||D041|0448|0|V25|37| FR|01220||S179180,S182183,S801807,S838839,S842,S845,S874875|||D041|0448|7|V25|37| FR|01230|||||D041|0448|0|V14|37| FR|01230|||CIT,GEXAP||D016|1069|3|3|37| FR|01230||S293|GCHRF,GEAFR,GEDOM||D041|0448|0|V14|37| FR|01230||S314|CBE,CES,CNL,CRU,GCHRF,GEAFR,GEDOM||D041|0448|7|V14|37| FR|01230||S882|||D041|0448|7|V14|37| FR|01230||S327328|||D016|1069|3|3|37| FR|01230||S299,S302303|CBE,CES,CNL,CRU,GCHRF,GEAFR,GEDOM||D041|0448|0|V14|37| FR|01230||S179180,S182183,S801807,S838839,S842,S845,S874875|||D041|0448|7|V14|37| FR|01240|||||D041|0435|5|P20|37| FR|01240|||CIT,GEXAP||D016|1069|3|110|37| FR|01240||S293|GCHRF,GEAFR,GEDOM||D041|0435|0|P20|37| I know that I could use an explode('|', $var) etc etc .. But how can I read in the file and tell to my script that he needs to read in the file so that I can explode the variables etc .?? Is it something like fread(filename) ? Thanks Link to comment https://forums.phpfreaks.com/topic/167268-import-file-using-php-script/ Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 $file = 'some_file_name.txt'; foreach(file($file) as $line){ $data = explode('|',$line); print $data[0]; } Link to comment https://forums.phpfreaks.com/topic/167268-import-file-using-php-script/#findComment-881934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.