: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ($is_list) { // Selector List
if (count($result) > 0) { $selectors[] = $result; }
if (isset($this->attr[$name])) {
return $this->convert_text($this->attr[$name]);
case 'outertext': return $this->outertext();
case 'innertext': return $this->innertext();
case 'plaintext': return $this->text();
case 'xmltext': return $this->xmltext();
default: return array_key_exists($name, $this->attr);
function __set($name, $value)
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
case 'outertext': return $this->_[HDOM_INFO_OUTER] = $value;
if (isset($this->_[HDOM_INFO_TEXT])) {
return $this->_[HDOM_INFO_TEXT] = $value;
return $this->_[HDOM_INFO_INNER] = $value;
if (!isset($this->attr[$name])) {
$this->_[HDOM_INFO_SPACE][] = array(' ', '', '');
$this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE;
$this->attr[$name] = $value;
case 'outertext': return true;
case 'innertext': return true;
case 'plaintext': return true;
//no value attr: nowrap, checked selected...
return (array_key_exists($name, $this->attr)) ? true : isset($this->attr[$name]);
if (isset($this->attr[$name])) { unset($this->attr[$name]); }
function convert_text($text)
if (is_object($debug_object)) { $debug_object->debug_log_entry(1); }
$sourceCharset = strtoupper($this->dom->_charset);
$targetCharset = strtoupper($this->dom->_target_charset);
if (is_object($debug_object)) {
$debug_object->debug_log(3,
if (!empty($sourceCharset)
&& !empty($targetCharset)
&& (strcasecmp($sourceCharset, $targetCharset) != 0)) {
// Check if the reported encoding could have been incorrect and the text is actually already UTF-8
if ((strcasecmp($targetCharset, 'UTF-8') == 0)
&& ($this->is_utf8($text))) {
$converted_text = iconv($sourceCharset, $targetCharset, $text);
// Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
if ($targetCharset === 'UTF-8') {
if (substr($converted_text, 0, 3) === "\xef\xbb\xbf") {
$converted_text = substr($converted_text, 3);
if (substr($converted_text, -3) === "\xef\xbb\xbf") {
$converted_text = substr($converted_text, 0, -3);
static function is_utf8($str)
for($i = 0; $i < $len; $i++) {
if(($c >= 254)) { return false; }
elseif($c >= 252) { $bits = 6; }
elseif($c >= 248) { $bits = 5; }
elseif($c >= 240) { $bits = 4; }
elseif($c >= 224) { $bits = 3; }
elseif($c >= 192) { $bits = 2; }
if(($i + $bits) > $len) { return false; }
if($b < 128 || $b > 191) { return false; }
function get_display_size()
if ($this->tag !== 'img') {
// See if there is aheight or width attribute in the tag itself.
if (isset($this->attr['width'])) {
$width = $this->attr['width'];
if (isset($this->attr['height'])) {
$height = $this->attr['height'];
// Now look for an inline style.
if (isset($this->attr['style'])) {
// Thanks to user gnarf from stackoverflow for this regular expression.
'/([\w-]+)\s*:\s*([^;]+)\s*;?/',
foreach ($matches as $match) {
$attributes[$match[1]] = $match[2];
// If there is a width in the style attributes:
if (isset($attributes['width']) && $width == -1) {
// check that the last two characters are px (pixels)
if (strtolower(substr($attributes['width'], -2)) === 'px') {
$proposed_width = substr($attributes['width'], 0, -2);
// Now make sure that it's an integer and not something stupid.
if (filter_var($proposed_width, FILTER_VALIDATE_INT)) {
$width = $proposed_width;
// If there is a width in the style attributes:
if (isset($attributes['height']) && $height == -1) {
// check that the last two characters are px (pixels)
if (strtolower(substr($attributes['height'], -2)) == 'px') {
$proposed_height = substr($attributes['height'], 0, -2);
// Now make sure that it's an integer and not something stupid.
if (filter_var($proposed_height, FILTER_VALIDATE_INT)) {
$height = $proposed_height;
// Look in the tag to see if there is a class or id specified that has
// a height or width attribute to it.
// Far future enhancement
// Look at all the parent tags of this image to see if they specify a
// class or id that has an img selector that specifies a height or width
// Note that in this case, the class or id will have the img subselector
// for it to apply to the image.
// ridiculously far future development
// If the class or id is specified in a SEPARATE css file thats not on
// the page, go get it and do what we were just doing for the ones on
function save($filepath = '')
$ret = $this->outertext();
file_put_contents($filepath, $ret, LOCK_EX);
function addClass($class)
$class = explode(' ', $class);
if (isset($this->class)) {
if ($this->hasClass($c)) {
$this->class .= ' ' . $c;
if (isset( $debug_object) && is_object($debug_object)) {
$debug_object->debug_log(2, 'Invalid type: ', gettype($class));
function hasClass($class)
if (isset($this->class)) {
return in_array($class, explode(' ', $this->class), true);
if (isset( $debug_object) && is_object($debug_object)) {
$debug_object->debug_log(2, 'Invalid type: ', gettype($class));
function removeClass($class = null)
if (!isset($this->class)) {
$this->removeAttribute('class');
$class = explode(' ', $class);
$class = array_diff(explode(' ', $this->class), $class);
$this->removeAttribute('class');
$this->class = implode(' ', $class);
function getAllAttributes()
function getAttribute($name)
return $this->__get($name);
function setAttribute($name, $value)
$this->__set($name, $value);
function hasAttribute($name)
return $this->__isset($name);
function removeAttribute($name)
$this->__set($name, null);
$this->parent->removeChild($this);
function removeChild($node)
$nidx = array_search($node, $this->nodes, true);
$cidx = array_search($node, $this->children, true);
$didx = array_search($node, $this->dom->nodes, true);
if ($nidx !== false && $cidx !== false && $didx !== false) {
foreach($node->children as $child) {
$node->removeChild($child);
foreach($node->nodes as $entity) {
$enidx = array_search($entity, $node->nodes, true);
$edidx = array_search($entity, $node->dom->nodes, true);
if ($enidx !== false && $edidx !== false) {
unset($node->nodes[$enidx]);
unset($node->dom->nodes[$edidx]);
unset($this->nodes[$nidx]);
unset($this->children[$cidx]);
unset($this->dom->nodes[$didx]);
function getElementById($id)
return $this->find("#$id", 0);
function getElementsById($id, $idx = null)
return $this->find("#$id", $idx);
function getElementByTagName($name)
return $this->find($name, 0);
function getElementsByTagName($name, $idx = null)
return $this->find($name, $idx);
function childNodes($idx = -1)
return $this->children($idx);
return $this->first_child();
return $this->last_child();
return $this->next_sibling();
function previousSibling()
return $this->prev_sibling();
return $this->has_child();
function appendChild($node)
/** @var null | simple_html_dom_node */
public $lowercase = false;
protected $noise = array();
protected $token_blank = " \t\r\n";
protected $token_equal = ' =/>';
protected $token_slash = " />\r\n\t";
protected $token_attr = ' >';
public $_target_charset = '';
protected $default_br_text = '';
public $default_span_text = '';
protected $self_closing_tags = array(
protected $block_tags = array(
protected $optional_closing_tags = array(
// https://www.w3.org/TR/html/textlevel-semantics.html#the-b-element
'dd' => array('dd' => 1, 'dt' => 1),
// https://www.w3.org/TR/html/grouping-content.html#the-dl-element
'dl' => array('dd' => 1, 'dt' => 1),
'dt' => array('dd' => 1, 'dt' => 1),
'li' => array('li' => 1),
'optgroup' => array('optgroup' => 1, 'option' => 1),
'option' => array('optgroup' => 1, 'option' => 1),