Search code examples
phpdomparsersimpledom

concatenate div into scraped content


I'm using PHP simple dom parser, how should I insert extra entities within them? like $html contain

<table class="tb">..</table>
<table>..</table>
<table>..</table>

I know how to select the dom, like $html->find('div[class="tb"][1]'); but how to concatenate new div after it? like I want to put ads btw table.


Solution

  • if you still want simpledom example:

    $banner = '<div class="ads">blablabla</div>';
    $tables = $html->find('table');
    foreach($tables as $table){
        $table->outertext .= $banner;
    }
    

    OR:

    $html->find('div[class="tb"][1]').outertext .= '<div class="ads">blablabla</div>';
    

    made after reading docs from here (: