preg_match_all найти текст между двумя словами, распечатать

я хочу получить все HTML-классы, которые являются VIP, и распечатать каждый результат VIP

$text = "<enty> hello baby, we love osama:) That means 2016 set a global heat record<enty2016>for the third year in a row</enty2016>according to NOAA and NASA, who held a joint press conference on Wednesday to discuss the record. <endentry> <enty2016>Temperatures over the Earth's continents and oceans in 2016 were 1.1 degree Celsius (1.98 degrees Fahrenheit) </enty2016>above the pre-industrial average, according to the WMO. That means we are already a <endline>majority of the way to the 1.5-degree warming goal <endenty> ";

я хочу напечатать все данные в enty2016s

preg_match("/<enty2016>(.*?)<\/enty2016>/is", $html, $matches);
foreach($matches[1] as $enty2016s){
echo $enty2016s;
}

1

Решение

я использую DOMDocument в комбинации с DOMXPath:

$dom = new DOMDocument;
$dom->loadHTML($html);

$xp = new DOMXPath($dom);
$divNodeList = $xp->query('//div[@class="vip"]/text()');

foreach ($divNodeList as $divNode) {
echo $divNode->nodeValue . PHP_EOL;
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector