first I let the it find the element
$dom= new \DOMDocument();
$dom->loadHTML($html_string);
$only_p = $dom->getElementsByTagName('p')->item(1);
If I try something like
$only_p->textContent; /* <-- it will only return the text inside the paragraph and even remove all the tags inside of it */
what I need is something like
$only_p = $dom->getElementsByTagName('p')->item(1);
$only_p->outerHTML;
that would return the HTML around it, like
<p class="something"><a href="link"> this is text </a></p>
instead of just the string "this is text"
$only_p->ownerDocument->saveXML($only_p);