【发布时间】:2013-07-08 14:39:28
【问题描述】:
我正在开发一个多平台应用程序,我必须在 php 中使用 preg_match_all 函数,但我无法以正确的方式使用它。
<div id="menu_background" style="background-image:url(images/menu_back_aylik.png);width:279px;height:164px;">
<div id="menu_header"><div class="one_menu_date" style="margin-left:94px;">**Çrş. 10.07.2013**</div>
<div onclick="next();" id="nextMenu"></div>
</div>
<div id="menu_container" style="margin-left:30px;margin-top:16px;">
<div id="menu_slider" style="width:17889px;">
<div class="one_menu">
<div class="one_lunchMainMenu">**lunch menu**</div>
<div class="one_lunchAltMenu">**lunch menu alternative**</div>
<div class="one_dinnerMainMenu">**dinner menu**</div>
<div class="one_dinnerAltMenu">**dinner menu alternative**</div>
</div>
</div>
</div>
10.07.2013 是今天的日期
我想将 lunch menu 分配给 $lunch,lunch menu alternative 分配给 $lunch_a,但我对 preg_match_all 了解不多。
有人可以帮我吗?
编辑:我正在尝试从另一个网站获取午餐菜单
edit2:我在使用 regex
时遇到问题【问题讨论】:
-
不要使用正则表达式解析 HTML。您无法使用正则表达式可靠地解析 HTML,并且您将面临悲伤和挫败感。一旦 HTML 与您的期望发生变化,您的代码就会被破坏。有关如何使用已经编写、测试和调试的 PHP 模块正确解析 HTML 的示例,请参阅 htmlparsing.com/php。
标签: php regex html-parsing preg-match preg-match-all