summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2018-10-17 18:52:02 +0100
committerAndres Rey <[email protected]>2018-10-17 18:52:02 +0100
commit8bac6550009f575214330dc96af802a5767288c4 (patch)
treea9939d5e7475cb17cefbc9139289628b5649dc46 /src
parent6f7492a946860b2ff85cea707ccc873b79614234 (diff)
Improve script node removing function
Diffstat (limited to 'src')
-rw-r--r--src/Readability.php14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/Readability.php b/src/Readability.php
index d44052d..2f8b22f 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -782,16 +782,10 @@ class Readability
*/
private function removeScripts(DOMDocument $dom)
{
- $toRemove = ['script', 'noscript'];
-
- foreach ($toRemove as $tag) {
- while ($script = $dom->getElementsByTagName($tag)) {
- if ($script->item(0)) {
- $script->item(0)->parentNode->removeChild($script->item(0));
- } else {
- break;
- }
- }
+ foreach (['script', 'noscript'] as $tag) {
+ $nodes = $dom->getElementsByTagName($tag);
+ foreach (iterator_to_array($nodes) as $node)
+ NodeUtility::removeNode($node);
}
}