如何仅使用PHP从文件中获取特定内容。如何仅使用PHP从文件中获取特定内容。
我有内容的文件:在阵列
reference 1.pdb
mobile 4r_1.pdb
ignore
fit
mobile 4r_10.pdb
ignore
fit
mobile 4r_22220.pdb
ignore
fit
现在,我想利用所有的名字,即(输出)
4r_1
4r_10
4r_22220
并打印。
我已经用PHP编写的程序无法正常工作,可以看看
$data = file_get_contents('file.txt'); // to read the file
$convert = explode("\n", $data); // take it in an array
$output4 = preg_grep("/mobile/i",$convert); //take only the line starts with mobile and put it in an array
if ($output4 !="/mobile/i")
{
print $output4;
print "\n";
}
请帮帮忙!只提取名称
尝试'var_dump($ output4);' – 2013-05-09 12:41:31
我可能会首先搜索包含'pdb'的行,然后找到最右边的空间,并且爆炸/保留最正确的值。 – Kermit 2013-05-09 12:42:07
在每行中查找'mobile'和substr右侧。 – 2013-05-09 12:44:14