diff --git a/src/PHPHtmlParser/Dom/Node/AbstractNode.php b/src/PHPHtmlParser/Dom/Node/AbstractNode.php
index 79beda5..97353c0 100644
--- a/src/PHPHtmlParser/Dom/Node/AbstractNode.php
+++ b/src/PHPHtmlParser/Dom/Node/AbstractNode.php
@@ -114,6 +114,8 @@ public function __get(string $key)
return $this->outerHtml();
case 'innerhtml':
return $this->innerHtml();
+ case 'innertext':
+ return $this->innerText();
case 'text':
return $this->text();
case 'tag':
diff --git a/src/PHPHtmlParser/Dom/Node/HtmlNode.php b/src/PHPHtmlParser/Dom/Node/HtmlNode.php
index 95b369f..d60d4b8 100644
--- a/src/PHPHtmlParser/Dom/Node/HtmlNode.php
+++ b/src/PHPHtmlParser/Dom/Node/HtmlNode.php
@@ -27,6 +27,13 @@ class HtmlNode extends InnerNode
*/
protected $outerHtml;
+ /**
+ * Remembers what the innerText was if it was scanned previously.
+ *
+ * @var ?string
+ */
+ protected $innerText = null;
+
/**
* Remembers what the text was if it was scanned previously.
*
@@ -111,6 +118,21 @@ public function innerHtml(): string
return $string;
}
+ /**
+ * Gets the inner text of this node.
+ * @return string
+ * @throws ChildNotFoundException
+ * @throws UnknownChildTypeException
+ */
+ public function innerText(): string
+ {
+ if (is_null($this->innerText)) {
+ $this->innerText = strip_tags($this->innerHtml());
+ }
+
+ return $this->innerText;
+ }
+
/**
* Gets the html of this node, including it's own
* tag.
diff --git a/tests/DomTest.php b/tests/DomTest.php
index 1183128..6fd7d95 100755
--- a/tests/DomTest.php
+++ b/tests/DomTest.php
@@ -330,6 +330,16 @@ public function testEmptyAttribute()
$this->assertEquals(1, \count($items));
}
+ public function testInnerText()
+ {
+ $html = <<123456789101112