DOMWordsIterator
in package
implements
Iterator
FinalYes
Iterates individual words of DOM text and CDATA nodes while keeping track of their position in the document.
Example:
$doc = new DOMDocument(); $doc->load('example.xml'); foreach(new DOMWordsIterator($doc) as $word) echo $word;
Tags
Table of Contents
Interfaces
- Iterator
Properties
- $current : DOMElement|null
- $key : int|null
- $offset : int
- $start : DOMElement
- $words : array<int, array<int, int|string>>|null
Methods
- __construct() : mixed
- expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML)
- current() : string|null
- Return the current element
- currentElement() : DOMElement|null
- Returns DOMElement that is currently being iterated or NULL if iterator has finished.
- currentWordPosition() : array<string|int, mixed>
- Returns position in text as DOMText node and character offset.
- key() : int|null
- Return the key of the current element
- next() : void
- rewind() : void
- valid() : bool
- Checks if current position is valid
Properties
$current
private
DOMElement|null
$current
$key
private
int|null
$key
$offset
private
int
$offset
= -1
$start
private
DOMElement
$start
$words
private
array<int, array<int, int|string>>|null
$words
Methods
__construct()
expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML)
public
__construct(DOMNode $el) : mixed
Parameters
- $el : DOMNode
current()
Return the current element
public
current() : string|null
Tags
Return values
string|nullcurrentElement()
Returns DOMElement that is currently being iterated or NULL if iterator has finished.
public
currentElement() : DOMElement|null
Return values
DOMElement|nullcurrentWordPosition()
Returns position in text as DOMText node and character offset.
public
currentWordPosition() : array<string|int, mixed>
(it's NOT a byte offset, you must use mb_substr() or similar to use this offset properly). node may be NULL if iterator has finished.
Return values
array<string|int, mixed>key()
Return the key of the current element
public
key() : int|null
Tags
Return values
int|nullnext()
public
next() : void
rewind()
public
rewind() : void
valid()
Checks if current position is valid
public
valid() : bool