Removing script tag content from html source file
by guruprasad[ Edit ] 2014-05-29 19:20:45
To Remove the script tag contents from webpage/html sourced file:
Example,
<?php
$sampleHtml=file_get_contents("url of the page");
$dom = new DOMDocument();
$dom->loadHTML($sampleHtml);
$script = $dom->getElementsByTagName('script');
$keywordToremove = array();
foreach($script as $removingContents)
{
$keywordToremove[] = $removingContents;
}
foreach ($keywordToremove as $removingContents)
{
$removingContents->parentNode->removeChild($removingContents);
}
$sampleHtml = $dom->saveHTML();
?>
Note:
Helpful when needed to view source file without script contents.