1
первым я позволил ему найти элементКак получить HTML определенного тега с помощью PHP DomDocument
$dom= new \DOMDocument();
$dom->loadHTML($html_string);
$only_p = $dom->getElementsByTagName('p')->item(1);
Если я пытаюсь что-то вроде
$only_p->textContent; /* <-- it will only return the text inside the paragraph and even remove all the tags inside of it */
, что мне нужно что-то вроде
$only_p = $dom->getElementsByTagName('p')->item(1);
$only_p->outerHTML;
, который вернет HTML вокруг него, например
<p class="something"><a href="link"> this is text </a></p>
, а не только строки "это текст"
Вы можете попробовать '$ only_p-> ownerDocument-> saveXML ($ only_p);' – VolenD