Php 此代码中的preg_匹配
嗨,如果有人能帮我准备比赛,我想从这个代码中得到标题Php 此代码中的preg_匹配,php,preg-match,Php,Preg Match,嗨,如果有人能帮我准备比赛,我想从这个代码中得到标题 <dt class="gallery-icon"> <a href="?attachment_id=31" title="title"> <img width="150" height="150" src="librosdefirmas-bodas-1-150x150.jpg" class="attachment-thumbnail" alt="Caption"> &
<dt class="gallery-icon">
<a href="?attachment_id=31" title="title">
<img width="150" height="150" src="librosdefirmas-bodas-1-150x150.jpg" class="attachment-thumbnail" alt="Caption">
</a>
</dt>
我有这个:
preg_match_all('/<dt class="gallery-icon">\s*<a href="(.*)" title="(.*)".*>/is', $page_columns[0], $titles);
preg_match_all('/\s*/is',$page_列[0],$titles);
但是谁能帮我呢?这个“*”是一个贪婪的匹配,也就是说,如果后面有一个可以匹配的引用,它将徘徊在第一个引用之外。使用[^”]*代替。*匹配除引号外的所有字符。该“*”是贪婪匹配,即如果可以匹配后一个引号,它将徘徊在第一个引号之外。使用[^”]*代替。*匹配除引号外的所有字符。不要用正则表达式解析HTML
$html='1!'
';
$dom_document=新的DOMDocument();
$dom_document->loadHTML($html);
$dom_xpath=newdomxpath($dom_document);
$elements=$dom_xpath->query(“//dt/a”);
打印($elements->item(0)->getAttribute('title');
不要用正则表达式解析HTML
$html='1!'
';
$dom_document=新的DOMDocument();
$dom_document->loadHTML($html);
$dom_xpath=newdomxpath($dom_document);
$elements=$dom_xpath->query(“//dt/a”);
打印($elements->item(0)->getAttribute('title');
/\s*/是第一组中给出标题的完整模式/\s*/是第一组中给出标题的完整模式
$html = '
<dt class="gallery-icon">
<a href="?attachment_id=31" title="title">
<img width="150" height="150" src="librosdefirmas-bodas-1-150x150.jpg" class="attachment-thumbnail" alt="Caption">
</a>
</dt>
';
$dom_document = new DOMDocument();
$dom_document->loadHTML($html);
$dom_xpath = new DOMXpath($dom_document);
$elements = $dom_xpath->query("//dt/a");
print_r( $elements->item(0)->getAttribute('title') );