php open modify and save html file

后端 未结 3 685
忘了有多久
忘了有多久 2021-01-23 13:43

in php I would like to open a html file, delete the content of the div(class Areas) and save it.

$dom = new DOMDocument;
$dom->loadHTMLFile( \"temp/page\".$y.         


        
3条回答
  •  广开言路
    2021-01-23 14:21

    You want to remove the divs with class Area, so simply change the XPath query:

    $pDivs = $xpath->query(".//div[@class='Area']"); // not 'Areas'
    

    And of course you will also need to do something with the results, for example:

    echo htmlspecialchars($dom->saveHTML()); // prints the result
    

提交回复
热议问题