Parse a HTML document and get a specific element in PHP and save its HTML -


all want save first div attribute role="main" string external url using php.

so far have this:

$doc = new domdocument(); @$doc->loadhtmlfile("http://example.com/");  $xpath = new domxpath($doc); $elements = $xpath->query('//div[@role="main"]'); $str = ""; if ($elements->length > 0) {     $str = $elements->item(0)->textcontent; } echo htmlentities($str); 

but unfortunately $str not seem displaying html tags. text.

you can html via savehtml() method.

$str = $doc->savehtml($elements->item(0));


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -