Search code examples
phphtmlcsssimple-html-dom

Remove class and styling of h1 with simple_html_dom results


Following is my code:

$html = $_GET['html'];
$dom = file_get_html($html);
$h1 = $dom->find('h1');
echo $h1[0];

It returns the H1 text, but along with the class its originally associated with. Like:

<h1 class="postpageheading">the returned text </h1>

I want only the text, without even the tag.

How do i do this ? Thanks.


Solution

  • Try:

    echo $h1[0]->plaintext;
    

    From your file_get_html method it looks like you're using the PHP Simple HTML DOM Parser.

    If you look at their Quick Start here:

    http://simplehtmldom.sourceforge.net/

    Click on the tab "Extract contents from HTML" and it shows how to use this plaintext to get the contents without tags.