<h3 class="r"><a href="http://www.163.com/" target=_blank class=l onmousedown="IID()">网易 <b>...</b>....</a>。
<h3 class="r"><a href="http://www.sina.com/" target=_blank class=l onmousedown="IID()">新浪</a>........
<h3 class="r"><a href="http://www.qq.com/" target=_blank class=l onmousedown="IID()">腾讯</a>........例如上面一段代码,一个html页面里面有许多“<h3 class="r">”,我想把所有“<h3 class="r">”后面的第一个链接(<a></a>)中的内容取出来。
比如第一个,<h3 class="r"><a href="http://www.163.com/" target=_blank class=l onmousedown="IID()">网易 <b>...</b>....</a>。
我想得到的是网易 ,依此类推全有的“<h3 class="r">”后面的第一个链接(<a></a>)中的内容都取出来。帮帮忙吧.
<h3 class="r"><a href="http://www.sina.com/" target=_blank class=l onmousedown="IID()">新浪</a>........
<h3 class="r"><a href="http://www.qq.com/" target=_blank class=l onmousedown="IID()">腾讯</a>........例如上面一段代码,一个html页面里面有许多“<h3 class="r">”,我想把所有“<h3 class="r">”后面的第一个链接(<a></a>)中的内容取出来。
比如第一个,<h3 class="r"><a href="http://www.163.com/" target=_blank class=l onmousedown="IID()">网易 <b>...</b>....</a>。
我想得到的是网易 ,依此类推全有的“<h3 class="r">”后面的第一个链接(<a></a>)中的内容都取出来。帮帮忙吧.
$dom = new DOMDocument('1.0', 'GBK');
$dom->loadHTML($url);$ret = array();$xpath = new DOMXPath($dom);$query = '//html/body..../h3@[class="r"]/a';$entries = $xpath->query($query);何必非要正则呢,不过你既然要了就给你吧
<h3 class="r"><a href="http://www.sina.com/" target=_blank class=l onmousedown="IID()">新浪</a><h3\s*class="r"\s*>\s*<a[^>]+>(.*?)</a>