DOMDOCUMENT | PHP: save getElementById output into new HTML file -


i'm trying save result of getelementbyid using php.

the code have:

<?php $doc = new domdocument(); $doc->validateonparse = true; @$doc->loadhtmlfile('test.htm'); $div = $doc->getelementbyid('storytext'); echo $doc->savehtml($div); ?> 

this displays relevant text, want save new file, have tried using save(), savehtmlfile() , file_put_contents(), none of work because save strings , cannot turn $div string, i'm stuck.

if save entire thing:

$doc->savehtmlfile('name.ext'); 

it works saves everything, not part need.

i'm complete dom noob may missing simple can't find through searches.

function getinnerhtml( $node ) {      $innerhtml= '';      $children = $node->childnodes;      foreach ($children $child) {          $innerhtml .= $child->ownerdocument->savexml( $child );      }       return $innerhtml;  }  $html = getinnerhtml($div); file_put_contents("name.ext", $html); 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -