Php 使用正则表达式获取按钮html部分(preg_match_all)
下面是我的htmlPhp 使用正则表达式获取按钮html部分(preg_match_all),php,regex,Php,Regex,下面是我的html $testHtml ='<div class="product-info" style="min-height: 190px;"> <h2 class="product-name"><a title="Ottoman" href="">Ottoman</a></h2> <div class="price-box"> <span id
$testHtml ='<div class="product-info" style="min-height: 190px;">
<h2 class="product-name"><a title="Ottoman" href="">Ottoman</a></h2>
<div class="price-box">
<span id="product-price-51" class="regular-price">
<span class="price">$299.99</span></span>
</div>
<div class="ratings">
<div class="rating-box">
<div style="width:69%" class="rating"></div>
</div>
<span class="amount"><a onclick="var t = opener ? opener.window : window; t.location.href=''; return false;" href="#">4 Review(s)</a></span>
</div>
<div class="actions">
<button onclick="setLocation('')" class="button btn-cart" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button>
<ul class="add-to-links">
<li><a class="link-wishlist" href="">Add to Wishlist</a></li>
<li><span class="separator">|</span><a class="link-compare" href="/">Add to Compare</a></li>
</ul>
</div>
</div>';
我只想要下面这样的按钮标签
<button onclick="setLocation('')" class="button btn-cart" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button>
什么是preg_match_all expression您可以尝试以下方法:
$pattern = '/(<button.*)/';
$result = preg_match($html, $pattern);
你读过吗?对HTML使用RegExp是一个非常糟糕的主意。可能的重复使用zend_dom_查询是否可能?