Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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/8/.htaccess/6.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 使用正则表达式(抓取数据)解析HTML并获取具有日期信息的多维数组?_Php_Regex_Date_Html Parsing - Fatal编程技术网

Php 使用正则表达式(抓取数据)解析HTML并获取具有日期信息的多维数组?

Php 使用正则表达式(抓取数据)解析HTML并获取具有日期信息的多维数组?,php,regex,date,html-parsing,Php,Regex,Date,Html Parsing,我试着把我得到的结果按日期分组 请参考我前面的问题。 基本上现在我得到了时间表列表,但其中不包括任何日期,因此很难理解哪个事件将在哪个日期和时间上线,因为没有日期,这让人困惑,因为它显示了多个事件的相同时间,而这些事件实际上将在不同的日期上线 从上一个问题中,我得到了一个完美的解决方案(谢谢你的解决方案!),但没有日期 以下是解决方案正则表达式: <font(?=\s|>)(?=(?:[^>=|&)]*|='[^']*'|="[^"]*"|=[^'"][^\s>

我试着把我得到的结果按日期分组

请参考我前面的问题。

基本上现在我得到了时间表列表,但其中不包括任何日期,因此很难理解哪个事件将在哪个日期和时间上线,因为没有日期,这让人困惑,因为它显示了多个事件的相同时间,而这些事件实际上将在不同的日期上线

从上一个问题中,我得到了一个完美的解决方案(谢谢你的解决方案!),但没有日期

以下是解决方案正则表达式:

<font(?=\s|>)(?=(?:[^>=|&)]*|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\scolor=['"]?green['"]?)(?:[^>=|&)]|='(?:[^']|\\')*'|="(?:[^"]|\\")*"|=[^'"][^\s>]*)*>\s*(?:Stream\s*)?((?:(?!<\/font>).)*)<\/font>\s*[^<]*?([^<]+)\s+(\d+.\d+\s*\w{2}\s*-\s*\d+.\d+\s*\w{2})[^<]*?<font(?=\s|>)(?=(?:[^>=|&)]*|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\scolor=['"]?gold['"]?)(?:[^>=|&)]|='(?:[^']|\\')*'|="(?:[^"]|\\")*"|=[^'"][^\s>]*)*>(?:Stream\s*)?((?:(?!\s*https?:|<\/font>).)*)
示例输出只是随机生成的输出,而不是真实的数据或任何东西

有人能帮忙吗?非常感谢


注意:我不想使用任何HTML解析库,所以请不要推荐,除非您有比我现在使用的regex更好的解决方案。

您不想使用HTML解析的具体原因是什么?对于给定的HTML,它感觉比正则表达式更容易——迭代字体标记将非常容易,然后您可以更容易地根据它们的内容分析它们。(除非页面的HTML没有正确验证,并且破坏了PHPDOM函数)我觉得正则表达式是直截了当的,是的,HTML内容没有验证,它非常混乱(没有结束标记等等)。我确实尝试过HTML解析,但这使它变得更加复杂(也许我没法得到那么多)。但是正如我所说的,如果有人有使用HTML解析库的解决方案,那么我只能切换到这个解决方案(如果不复杂的话:D)。不要使用正则表达式解析HTML。使用适当的HTML解析模块。您无法用正则表达式可靠地解析HTML,在这条路上您将面临悲伤和挫折。一旦HTML改变了您的预期,您的代码就会被破坏。有关如何使用已编写、测试和调试的PHP模块正确解析HTML的示例,请参阅或。@AndyLester:但我无法使用HTML解析器解析和获取所需的输出:|您知道如何做吗?请张贴解决方案,如果你可以,将是伟大的和有益的!关于如何做到这一点,有很多例子。我刚刚发布了一个链接,但是还有很多其他的链接。查找文档。尽你所能尝试一下,如果它不起作用,就在不起作用的解析器的基础上发布一个新问题。
<font color="black" size="6">---</font><p>
<font color="red" size="6">FRIDAY 6TH SEPTEMBER</font><p>
<font color="gold"> *ENGLISH* </font> Some event with quotes, comma, slashes, dots and more 9.00pm-5.00pm <font color="red">Channel 18</font><p>
<font color="gold"> *ITALIAN* </font> Some event with quotes, comma, slashes, dots and more 9.50pm-10.00pm <font color="red">Channel 02</font><p>
<font color="gold"> *ENGLISH* </font> Some event with quotes, comma, slashes, dots and more 10:00AM-12:00pm <font color="red">Channel 05</font><p>
<font color="gold"> *JAPANESE* </font> Some Event Name 11.20am-1.20pm <font color="red">CHANNEL IP 2 STREAM http://domain.com/abc/channel2.html</font><p>
<font color="black" size="6">---</font><p>
<font color="red" size="6">FRIDAY 7TH SEPTEMBER</font><p>
<font color="gold"> *ENGLISH* </font> Some event with quotes, comma, slashes, dots and more 9.00pm-5.00pm <font color="red">Channel 18</font><p>
<font color="gold"> *ITALIAN* </font> Some event with quotes, comma, slashes, dots and more 9.50pm-10.00pm <font color="red">Channel 02</font><p>
<font color="gold"> *ENGLISH* </font> Some event with quotes, comma, slashes, dots and more 10:00AM-12:00pm <font color="red">Channel 05</font><p>
<font color="gold"> *JAPANESE* </font> Some Event Name 11.20am-1.20pm <font color="red">CHANNEL IP 2 STREAM http://domain.com/abc/channel2.html</font><p>
Array(
  ['2013-09-06'] => Array (
    [0] => Array (
      'language'   => 'ENGLISH',
      'title'      => 'Some event name',
      'startTime'  => '9:00pm',
      'endTime'    => '5:00pm',
      'channel'    => 'channel 18',
      'channelNum' => '18'
    ),
    [1] => Array (
      'language'   => 'ITALIAN',
      'title'      => 'Some event name',
      'startTime'  => '12:00pm',
      'endTime'    => '2:00pm',
      'channel'    => 'Channel IP 2',
      'channelNum' => '2'
    ),
    [2] => Array (
      'language'   => 'ENGLISH',
      'title'      => 'Some event name',
      'startTime'  => '6:00pm',
      'endTime'    => '8:00pm',
      'channel'    => 'channel 20',
      'channelNum' => '20'
    ),
  ),
  ['2013-09-07'] => Array (
    [0] => Array (
      'language'   => 'ENGLISH',
      'title'      => 'Some event name',
      'startTime'  => '9:00pm',
      'endTime'    => '5:00pm',
      'channel'    => 'channel 18',
      'channelNum' => '18'
    ),
    [1] => Array (
      'language'   => 'ITALIAN',
      'title'      => 'Some event name',
      'startTime'  => '12:00pm',
      'endTime'    => '2:00pm',
      'channel'    => 'Channel IP 2',
      'channelNum' => '2'
    ),
    [2] => Array (
      'language'   => 'ENGLISH',
      'title'      => 'Some event name',
      'startTime'  => '6:00pm',
      'endTime'    => '8:00pm',
      'channel'    => 'channel 20',
      'channelNum' => '20'
    ),
  ),
)