Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用正则表达式和php从txt文件中提取ID_Php_Regex - Fatal编程技术网

使用正则表达式和php从txt文件中提取ID

使用正则表达式和php从txt文件中提取ID,php,regex,Php,Regex,我已经花了两个多小时试着让它工作 我想提取 之间的值:“ 和,“工程数据& 文本在这里 输出应该是一个超过300个ID的列表,但我只得到一个 当我运行脚本时 <? php //First, open the file. Change your filename $file = "http://fdguirhgeruih.x10.mx/html.txt"; $word1='&quot;:&quot;'; $word2='&quot

我已经花了两个多小时试着让它工作 我想提取

之间的值:“

,“工程数据&

文本在这里

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

当我运行脚本时

 <? 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文件。

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

用于解析它而不是regexp

内容是HTML,而不是第一个答案中提到的XML。使用。

内容是HTML,而不是第一个答案中提到的XML。使用.

+1,但是本机PHP DOM库是更好的选择。看到很多简单的HTMLDOM解析器,原生DOM可能比简单的HTMLDOM解析器更好。我不知道它维护得有多好,因为我已经有一段时间不需要它了。@itay不总是正确的。XHTML是XML,但如果您查看他的源文档,就XML而言,它有许多无效的标记。例如,img标记没有有效XML中所需的闭包。+1但是本机PHP DOM库是更好的选择。看到很多简单的HTMLDOM解析器,原生DOM可能比简单的HTMLDOM解析器更好。我不知道它维护得有多好,因为我已经有一段时间不需要它了。@itay不总是正确的。XHTML是XML,但如果您查看他的源文档,就XML而言,它有许多无效的标记。例如,img标记没有有效XML所需的闭包。