Habari\HTMLTokenSet::slice PHP Method

slice() public method

Fetch a section of the tokens, based on passed criteria
public slice ( mixed $names, array $attr = null ) : array
$names mixed The name of an html tag, or an array of names of html tags to get the tokens of
$attr array Any attributes for the token that you want to filter by
return array An array of the HTMLTokenSets that were found
    public function slice($names, array $attr = null)
    {
        $names = (array) $names;
        $ret = array();
        foreach ($names as $name) {
            $offset = 0;
            $slices = array();
            while ($slice = $this->find_slice($offset, $name, $attr)) {
                $slices[] = $slice;
                $offset = $slice->get_end_offset();
            }
            // Need to reverse this because we need to splice the last chunks first
            // if we splice the earlier chunks first, then the offsets get all
            // messed up. Trust me.
            $ret = array_merge($ret, array_reverse($slices));
        }
        return $ret;
    }