Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to get the plaintext using php domdocument

I am trying to get the plaintext from the given html. But, it is not possible for me. for this, what I had done is

My html is in $content variable

Now, I am passing $content variable to php DomDocuemnt

$d = new DOMDocument();
@$d->loadHTML($content)

Whats my next step to get the plaintext from the obtained html.

Please help me in this. Thanks in advance!

like image 997
Gireesh Avatar asked Oct 20 '22 15:10

Gireesh


1 Answers

I can't understand your question but if you want the HTML code as string then Try this...

$d = new DOMDocument();
$d->loadHTML($content);
$plainText = $d->textContent;
echo $plainText;
like image 180
Vegeta Avatar answered Oct 27 '22 11:10

Vegeta