정규 표현식에 대해 더 알고 싶다면 좋은 책을 구입하는 것이 좋습니다. 또는 좋은 자습서 용 Google. 개인적으로 내가 좋아하는 것 regular-expressions.info
preg_match_all
에 관한 모든 정보는 공식 문서 here
에서 찾을 수 있습니다. PHP 커뮤니티는 보통 매뉴얼 페이지에서 유용한 코드를 공유한다. 나는 당신이 원하는 정보를 찾을 수 있다고 생각한다. 당신은 페이지의 전체 HTML 콘텐츠를 구문 분석하는 경우
php > $ch = curl_init('http://stackoverflow.com/questions/7883392/preg-match-all-output-all-h-tags-with-type');
php > curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $data = curl_exec($ch);
php > preg_match_all("!<h(\d)[^>]*>(.*?)</h\\1>!ism",$data,$headings);
php > var_export($headings);
array (
0 =>
....
2 =>
array (
0 => '<a href="https://stackoverflow.com/questions/7883392/preg-match-all-output-all-h-tags-with-type" class="question-hyperlink">preg_match_all output all h tags with type</a>',
1 => '',
2 => '
Know someone who can answer?
Share a <a href="https://stackoverflow.com/q/7883392">link</a> to this question via
<a href="mailto:?subject=Stack%20Overflow%20Question&body=preg_match_all%20output%20all%20h%20tags%20with%20type%0Ahttp%3a%2f%2fstackoverflow.com%2fq%2f7883392">email</a>,
<a href="http://twitter.com/share?url=http%3a%2f%2fstackoverflow.com%2fq%2f7883392&text=preg_match_all%20output%20all%20h%20tags%20with%20type">twitter</a>, or
<a href="http://www.facebook.com/sharer.php?u=http%3a%2f%2fstackoverflow.com%2fq%2f7883392&t=preg_match_all%20output%20all%20h%20tags%20with%20type">facebook</a>.
',
3 => 'Your Answer',
4 => '
Browse other questions tagged <a href="https://stackoverflow.com/questions/tagged/php" class="post-tag" title="show questions tagged \'php\'" rel="tag">php</a> <a href="https://stackoverflow.com/questions/tagged/preg-match-all" class="post-tag" title="show questions tagged \'preg-match-all\'" rel="tag">preg-match-all</a>
or <a href="https://stackoverflow.com/questions/ask">ask your own question</a>.
',
5 => 'Hello World!',
6 => 'Related',
),
)
은 첫째로 당신은 당신의 인생을 어떻게 든에 의존하지 않는 HTML/XML 등을 분석 할 정규식을 사용하지 않아야합니다. 둘째로 나는 "타입"이 무엇을 의미하는지 모른다. 구체적인 입력과 원하는 출력을 제공 할 수 있습니까? – FailedDev
미안 유형은 h 태그 (h1, h2, h3 등)의 종류입니다. 표 유형 및 내용 (실제 텍스트)을 원하면 사용해야합니까? –
'preg_match_all '의 네 번째 매개 변수로'PREG_SET_ORDER'가 누락되었습니다. – mario