使用regex和php从txt文件中提取ID


Extracting IDs from txt file using regex and php

我花了两个多小时试图让它发挥作用我想提取

":" 之间的值

","eng_data&

txt在这里http://fdguirhgeruih.x10.mx/html.txt

输出应该是300多个ID的列表,但我只得到一个

http://fdguirhgeruih.x10.mx/extract.php

当我运行脚本时

 <? php
    //First, open the file. Change your filename
    $file = "http://fdguirhgeruih.x10.mx/html.txt";
    $word1='&quot;:&quot;';
    $word2='&quot;,&quot;eng_data&';

    $contents = file_get_contents($file);
    $between=substr($contents, strpos($contents, $word1), strpos($contents, $word2) - strpos($contents, $word1));
    echo $between; 

    ?>

这看起来像一个标准的XML文件
使用simpleXML来解析它,而不是regexp

内容是HTML,而不是第一个答案所指出的XML。使用简单的html-dom解析器。