귀하의 질문에 오해가 없으면이 방법이 효과적입니다.
$html = '<a href="https://www.website.com/n/?confirm.php" ></a>';
preg_match_all('/href="([^\s"]+)/', $html, $match);
print '<pre>';
print_r($match);
print '</pre>';
print $match[1][0];
편집는 : 코멘트 당, 당신은 우리에게 그냥 href
를 캡처하는 일반적인 대답을 게시 왜 특정 URL을 제공하지 않았다. 내 아래 답변을 참조하십시오. 중고 정규식 https://regex101.com/r/pnfz7E/1
$re = '/<a href="([^"]*?\/n\/\?confirm\.php)">.*?<\/a>/m';
$str = '<a href="https://www.website.com/n/?noconfirm.php">SSD</a>
<div>How are you</div>
<a href="https://www.website.com/n/?confirm.php">HDD</a>
<h2>Being Sunny</h2>
<a href="https://www.ltmgtfu.com/n/?noconfirm.php">MSD</a>
<div>How are you</div>
<a href="https://www.website.com/n/?confirm.php"></a>
<h2>Being Sunny</h2>
<a href="https://www.google.com/n/?noconfirm.php">GSD</a>
<div>How are you</div>
<a href="https://www.website.com/n/?confirm.php">LSD</a>
<h2>Being Sunny</h2>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
print '<pre>';
print_r($matches);
print '</pre>';
이 한 번 봐 여기에서 찾을 수 : [XHTML 자체 포함 된 태그를 제외하고 정규식 일치 열린 태그 (https://stackoverflow.com/questions/1732348/regex-match-open- tags-except-xhtml-self-contained-tags/1732454 # 1732454) 및 이것 : [The DOMDocument class] (http://php.net/manual/de/class.domdocument.php) – insertusernamehere
모든 URL 추출 DOM 인 경우),'preg_grep'을 시도해 * 특정 부분 *을 포함하는 것을 출력하십시오. – revo
@revo 당신의 방식에 따라 어떤 대답입니까? –