如何在php中检测文本文件换行符?

时间:2012-04-03 19:47:40

标签: php arrays string

我有一个在记事本中创建的txt文件,包含这些行,例如:

lao_esan_ubon_444
chantrick
solikh
knalpoot
tanduy_007
Mario3010

现在我需要将每一行放在一个数组单元格中,如下所示:

array('lao_esan_ubon_444','chantrick','solikh','knalpoot','tanduy_007','Mario3010');

我如何使用PHP(长列表)?

2 个答案:

答案 0 :(得分:3)

使用file function

$array = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

请注意,flags参数(FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)仅适用于PHP 5或更高版本。

答案 1 :(得分:2)

<?php
$data=file_get_contents("your file name");
$array=explode("\n",$data);
?>

希望这会有所帮助

相关问题