Documentation

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
author

porneL http://pornel.net

license

Public Domain

url

https://github.com/antoligy/dom-string-iterators

implements

Table of Contents

Interfaces

Iterator

Properties

$current  : DOMElement|null
$key  : int|null
$letters  : array<int, string>|null
$offset  : int
$start  : DOMElement

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.
currentTextPosition()  : array<string|int, mixed>
Returns position in text as DOMText node and character offset.
key()  : int|null
next()  : void
rewind()  : void
valid()  : bool
Checks if current position is valid

Properties

Methods

__construct()

expects DOMElement or DOMDocument (see DOMDocument::load and DOMDocument::loadHTML)

public __construct(DOMNode $el) : mixed
Parameters
$el : DOMNode

currentElement()

Returns DOMElement that is currently being iterated or NULL if iterator has finished.

public currentElement() : DOMElement|null
Return values
DOMElement|null

currentTextPosition()

Returns position in text as DOMText node and character offset.

public currentTextPosition() : 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>

        
On this page

Search results