Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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 使用Preg Match分解html页面_Php_Html_Preg Match - Fatal编程技术网

Php 使用Preg Match分解html页面

Php 使用Preg Match分解html页面,php,html,preg-match,Php,Html,Preg Match,我目前得到一个html页面,其中包含谷歌排名最高的网站的数据,我需要的能力,以打破 <li class="g"><!--m--><div class="rc" data-hveid="74"><span class="altcts"></span><h3 class="r"><a href="http://airconditioning-london.co.uk/" onMouseDown="return rwt(th

我目前得到一个html页面,其中包含谷歌排名最高的网站的数据,我需要的能力,以打破

<li class="g"><!--m--><div class="rc" data-hveid="74"><span class="altcts"></span><h3 class="r"><a href="http://airconditioning-london.co.uk/" onMouseDown="return rwt(this,'','','','2','AFQjCNH1BqTrwsbjky2ajPKpf01lUuU_JA','','0CEsQFjAB','','',event)"><em>Air Conditioning London</em> | Installation | Repairs | Maintenance |</a></h3><div class="s"><div><div class="f kv" style="white-space:nowrap"><cite class="vurls"><b>airconditioning</b>-<b>london</b>.co.uk/</cite>‎<div class="action-menu ab_ctl"><a class="clickable-dropdown-arrow ab_button" href="#" id="am-b1" aria-label="Result details" jsaction="ab.tdd;keydown:ab.hbke;keypress:ab.mskpe" aria-expanded="false" aria-haspopup="true" role="button" data-ved="0CEwQ7B0wAQ"><span class="mn-dwn-arw"></span></a><div class="action-menu-panel ab_dropdown" jsaction="keydown:ab.hdke;mouseover:ab.hdhne;mouseout:ab.hdhue" role="menu" tabindex="-1" data-ved="0CE0QqR8wAQ"><ul><li class="action-menu-item ab_dropdownitem" role="menuitem"><a class="fl" href="http://webcache.googleusercontent.com/search?q=cache:4BhUc7PZJMgJ:airconditioning-london.co.uk/+&amp;cd=2&amp;hl=en&amp;ct=clnk&amp;gl=uk" onMouseDown="return rwt(this,'','','','2','AFQjCNHtODEWSJL7iUlNPyYez6IpTq8vUQ','','0CE4QIDAB','','',event)">Cached</a></li><li class="action-menu-item ab_dropdownitem" role="menuitem"><a class="fl" href="/search?pws=1&amp;igu=1&amp;gl=GB&amp;gll=53.41058,-2.97794&amp;near=london&amp;q=related:airconditioning-london.co.uk/+air+conditioning+london&amp;tbo=1&amp;sa=X&amp;ei=jjj6UvCmBoyHrAe18oDwAQ&amp;ved=0CE8QHzAB">Similar</a></li></ul></div></div></div><div class="f slp"></div><span class="st"><em>Air Conditioning London</em>, We are London&#39;s best Cooling contractor. A specialist in Installation, Repairs, Service, Maintenance. Residential &amp; Commercial.</span></div></div></div><!--n--></li>
我需要能够获得以下信息,我相信PregMatch将是完成这项工作的最佳方式

标记文本-我需要此标记之间的文本

标记链接-我需要能够从h3周围的链接获取URL 标记文本-我需要能够获取span标记中显示的文本

我希望有人能帮上忙

提前感谢

中的文本
您不应该使用正则表达式来操作DOM,而应该使用类似.preg_match的方法,除非数据从未更改,否则可能不适合这种情况。你最好使用DOM解析器。谢谢你的评论,我以前用过,所以我会继续,我觉得PregMatch更好。
    $h3content = preg_replace('/<h3\b[^>]>(.*?)</h3>/', '$1', $source1);

    # link around the H3 < span class=st > ???
    # what you mean?

    # <span class="st"> text that shows in the span tag
    $spanContent = preg_replace('/<span\s+class="st"\b[^>]>(.*?)</span>/', '$1', $source1);