的某些行我必须写一个解析器与结构的txt文件是这样的:读一个文本文件PHP
exampleOfSomething:95428,另一个实例:129,youNeedThis:491 \ n
另一个实例:30219,exampleOfSomething:4998,youNeedThis:492,
但有一个主要的问题 - 比如上例中 - 该文件不总是一个订单出来,有时我另一个实例之前“搞定“youNeedThis” “等,但结构
{变量}:{}值,
始终是相同的。我知道我在找什么(即我只想读取“anotherExample”的值)。当我得到这个号码我希望它把它写在单独的行一些txt文件:
从我迄今为止得到是从文件中写入每个号码单独的行,但我必须将它们过滤出来只包含我正在寻找的。是否有过滤了这一点,而无需做这样的事情的一种方式:
$c = 0;
if (fread($file, 1) == "a" && $c == 0) $c++;
if (fread($file, 1) == "n" && $c == 1) $c++;
if (fread($file, 1) == "o" && $c == 2) $c++;
// And here after I check if this is correct line, I take the number and write the rest of it to output.txt
也许你可以用正则表达式来完成整个事情,比如Alma Do Mundo在他们的答案中提出的建议。 – brianmearns