简体   繁体   中英

How can detect text file line breaks in php?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM