diff --git a/src/PHPHtmlParser/Dom/Node/TextNode.php b/src/PHPHtmlParser/Dom/Node/TextNode.php
index 1c8b646c..6f5c30c1 100644
--- a/src/PHPHtmlParser/Dom/Node/TextNode.php
+++ b/src/PHPHtmlParser/Dom/Node/TextNode.php
@@ -53,6 +53,9 @@ public function __construct(string $text, $removeDoubleSpace = true)
if ($replacedText === false) {
throw new LogicalException('mb_ereg_replace returns false when attempting to clean white space from "' . $text . '".');
}
+ if ($replacedText === null) {
+ throw new LogicalException('mb_ereg_replace encountered an invalid encoding for "' . $text . '".');
+ }
$text = $replacedText;
}