Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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部分(preg_match_all)_Php_Regex - Fatal编程技术网

Php 使用正则表达式获取按钮html部分(preg_match_all)

Php 使用正则表达式获取按钮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

下面是我的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="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_查询是否可能?