我有一个包含.txt文件的目录。在每个.txt文件中都是行,在彼此之下。第二行是类别行。一个 txt 文件如下所示:
id-12345678 // id line
sport // category line
应该从其他类别中排除几个类别名称,例如Offside和2019 我已经过滤了如下数组:
$blogfiles = glob("data/articles/*.txt"); // array with ALL blogfiles
$all_categories = array();
foreach($blogfiles as $blogfile) { // Loop through the blogfiles in the directory
$lines = file($blogfile, FILE_IGNORE_NEW_LINES); // all lines of the txt file into an array
$all_categories[] = $lines[1]; // category line (2nd line in txt file)
$excl_categories = array('Offside','2019'); // contains elements that should be excluded
$filtered_categories = array_diff($all_categories,$excl_categories); //new filtered array of categories
我需要的是一个数组,blogfiles其中的类别已被过滤。我不知道如何将相应的博客文件绑定到过滤后的数组
达令说