As this is a piece of HTML code, you can use the class DOMDocument
:
$qtd = '<div id="itens">
<span>
435 itens encontrados
</span>
</div>';
$doc = new \DOMDocument();
$doc->loadHTML($qtd);
$elements = $doc->getElementsByTagName("div");
echo $elements[0]->nodeValue;
In this way, the result of echo
would be the contents of div
, including the span
tag, as described in the question. But if the content you want is span
, just change the tag name to:
$doc->getElementsByTagName("div");
// -------------------------^
As follows:
$qtd = '<div id="itens"><span>435 itens encontrados</span></div>';
$doc = new \DOMDocument();
$doc->loadHTML($qtd);
$elements = $doc->getElementsByTagName("span");
echo $elements[0]->nodeValue;
The result will be:
435 itens encontrados