DOMLettersIterator
in package
implements
Iterator
FinalYes
Iterates individual characters (Unicode codepoints) 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 DOMLettersIterator($doc) as $letter) echo $letter;
NB: If you only need characters without their position in the document, use DOMNode->textContent instead.
Tags
Table of Contents
Interfaces
- Iterator
Properties
Methods
- __construct() : mixed
- expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML).
- current() : mixed
- currentElement() : DOMElement
- Returns DOMElement that is currently being iterated or NULL if iterator has finished.
- currentTextPosition() : array<string|int, DOMElement>|array<string|int, int>
- Returns position in text as DOMText node and character offset.
- key() : mixed
- next() : void
- rewind() : mixed
- valid() : mixed
- addToQueue() : void
- isTextNode() : bool
Properties
$current
private
mixed
$current
$key
private
mixed
$key
$letters
private
mixed
$letters
$offset
private
mixed
$offset
$queue
private
SplQueue
$queue
$start
private
mixed
$start
Methods
__construct()
expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML).
public
__construct(DOMDocument|DOMElement $el) : mixed
Parameters
- $el : DOMDocument|DOMElement
current()
public
current() : mixed
currentElement()
Returns DOMElement that is currently being iterated or NULL if iterator has finished.
public
currentElement() : DOMElement
Return values
DOMElementcurrentTextPosition()
Returns position in text as DOMText node and character offset.
public
currentTextPosition() : array<string|int, DOMElement>|array<string|int, int>
(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, DOMElement>|array<string|int, int>key()
public
key() : mixed
next()
public
next() : void
rewind()
public
rewind() : mixed
valid()
public
valid() : mixed
addToQueue()
private
addToQueue(DOMNode $node) : void
Parameters
- $node : DOMNode
isTextNode()
private
isTextNode(DOMNode $element) : bool
Parameters
- $element : DOMNode