Preg匹配问题与HTML字符


Preg Match Issue with HTML Chars

我真的不知道为什么这是不工作,因为我理解它(.*?)应该匹配所有字符。我有一种感觉,这可能与html中的特殊字符有关?

我的代码

preg_match( '/butt_box(.*?)img/',$return_string, $returned_val);

这是我试图提取的HTML(试图提取butt_box和第一个img标签之间的内容。

<table class="butt_box">
        <tbody><tr>
          <td style="width:100%;">
            <div class="product_box3_price" style="padding: 15px 0 0 0; text-align:center;"><strong>Price Unavailable</strong><br>
            </div>
          </td>
          <td>
            <div style="padding: 9px 0 6px 0"><a href="http://www.xxxxxx.com.au/index.php?main_page=product_info&amp;products_id=1399"><img src="includes/templates/theme243/buttons/english/button_goto_prod_details.gif" alt="Go To This Product's Detailed Information" title=" Go To This Product's Detailed Information " width="144" height="36"></a><br>
            </div>
          </td>
        </tr>
        </tbody>
</table>

您需要使用s PCRE修饰符来允许点匹配换行符。

preg_match( '/butt_box(.*?)img/s',$return_string, $returned_val);