我在文本文件中有一个字符串
haha ; J1.A1 DUT.A1 DUT.A2 C1.1 C2.1 ,
F2.1 F4.1 K1.1 ,
F2.1 F4.1 K1.1 ,
F2.1 F4.1 K1.1
aaa; J1.A1 DUT.A1 DUT.A2 C2.1 C3.1 ,
F3.1 F5.1 K2.1 ,
F3.1 F5.1 K2.1 ,
F3.1 F5.1 K2.1 我想像这样存储在数组中
$arr =array("haha J1.A1 DUT.A1 DUT.A2 C1.1 C2.1, F2.1 F4.1 K1.1, F2.1 F4.1 K1.1,F2.1 F4.1 K1.1", "aaa J1.A1 DUT.A1 DUT.A2 C2.1 C3.1, F3.1 F5.1 K2.1, F3.1 F5.1 K2.1, F3.1 F5.1 K2.1");如果逗号不在行中,则转到下一个数组字段
提前谢谢。
发布于 2012-07-02 00:43:30
尝试以下代码:
$file = 'my_file.txt';
$text = file_get_contents($file);
$lines = explode(',', $text);$text将包含文件的全部内容。
explode将在每个逗号上拆分$text。$lines将是一个字符串数组。
文档:
file_get_contents
explode
https://stackoverflow.com/questions/9738345
复制相似问题