You are here

protected function simple_html_dom::remove_noise in simplehtmldom API 6

Same name and namespace in other branches
  1. 5.2 simplehtmldom/simple_html_dom.php \simple_html_dom::remove_noise()
  2. 7 simplehtmldom/simple_html_dom.php \simple_html_dom::remove_noise()
1 call to simple_html_dom::remove_noise()
simple_html_dom::load in simplehtmldom/simple_html_dom.php

File

simplehtmldom/simple_html_dom.php, line 928

Class

simple_html_dom

Code

protected function remove_noise($pattern, $remove_tag = false) {
  $count = preg_match_all($pattern, $this->doc, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
  for ($i = $count - 1; $i > -1; --$i) {
    $key = '___noise___' . sprintf('% 3d', count($this->noise) + 100);
    $idx = $remove_tag ? 0 : 1;
    $this->noise[$key] = $matches[$i][$idx][0];
    $this->doc = substr_replace($this->doc, $key, $matches[$i][$idx][1], strlen($matches[$i][$idx][0]));
  }

  // reset the length of content
  $this->size = strlen($this->doc);
  if ($this->size > 0) {
    $this->char = $this->doc[0];
  }
}