I have a txt file that created in notepad , containing these lines for example :
lao_esan_ubon_444
chantrick
solikh
knalpoot
tanduy_007
Mario3010
Now i need to put every line in an array cell , like these:
array('lao_esan_ubon_444','chantrick','solikh','knalpoot','tanduy_007','Mario3010');
How can i do this with PHP (for long lists)?
Use the file
function.
$array = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
Note that the flags
parameter (FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
) is only available in PHP 5 or greater.
<?php
$data=file_get_contents("your file name");
$array=explode("\n",$data);
?>
hope this helps
file
function combines both of these - jnylen 2012-04-03 19:51