내가 문자열 (안 HTML 태그)정규식을 사용하여이 문자열 (html 태그)을 가져 오는 방법은 무엇입니까?
예컨대 있습니다
<div class="lh">
<b>Review: <b>Sarah Geronimo</b> leaves UAE fans asking for more</b></a><br>
<font size="-1"><b><font color="#6f6f6f">gulfnews.com</font></b></font><br>
<font size="-1"><b>Geronimo</b> how to get this contents <b>...</b></font><br>
<font size="-1" class="p"></font><br><font class="p" size="-1"><nobr><b>and more »</b></nobr></a></font>
</div>
내가 문자열을 얻을 원하는 "이 내용을 얻는 방법"을 참조하십시오. 내가 정규식으로 그것을 어떻게합니까?
이 경우
내가 정규식을 사용 왜 UPDATE?
$html = new simple_html_dom();
$html = file_get_html("https://news.google.com/news/feeds?q=sarah%20geronimo%20&output=rss");
foreach($html->find('item') as $item) {
$items['desc'] = $item->find('description',0)->plaintext;
$data[] = $items;
}
$regex = '~(?s)<div[^>]*>(?:.*?<font size){2}[^>]*><b>.*?</b>\K[^<]+~';
foreach($data as $content) {
$desc = $content['desc'];
preg_match($regex,$desc ,$m);
echo $m[0];
}
내가 태그 <description>
의 콘텐츠를 원하는 : 그것은 HTML 태그
을 포함 결과 때문에 나는이 사이트 https://news.google.com/news/feeds?q=sarah%20geronimo%20&output=rss
이 내 모든 코드를 분석하고 있습니다. 어떤 콘텐츠 html 태그를 포함하고 그것을 제거하는 정규식을 사용하고 있습니다
하지만 그 빈 공백? 이 정규식으로
정말로 DOM 파서가 아닌 정규식을 사용하고 싶습니까? –
예,이 경우에는 정규식이 필요하지 않습니다. DOM 파서 – Chielarck
DOM 파서를 사용하지 않는 이유는 무엇입니까? [당신은 정말로 그것을 고려해야한다] (http://stackoverflow.com/a/1732454/1594318). –