CakeFest 2024: The Official CakePHP Conference

DOMText::splitText

(PHP 5, PHP 7, PHP 8)

DOMText::splitText Quebra este nó em dois nós no deslocamento especificado

Descrição

public DOMText::splitText(int $offset): DOMText|false

Quebra este nó em dois no offset especificado, mantendo ambos na árvore como irmãos.

Depois de dividido, esse nó conterá todo o conteúdo até o offset. Se o nó original tinha um nó pai, o novo nó será inserido como o próximo irmão do nó original. Quando o offset for igual ao tamanho desse nó, o novo nó não terá dados.

Parâmetros

offset

O deslocamento para dividir, começando em 0.

Valor Retornado

O novo nó do mesmo tipo, que contém todo o conteúdo durante e após o offset.

add a note

User Contributed Notes 1 note

up
1
Flix Cloutier
10 years ago
It should be noted that $offset is a **character offset**, not a **byte offset**. This means that most other PHP string functions that deal with lengths and offsets (strlen, strpos, preg_match with PREG_OFFSET_CAPTURE, etc.) use and return values unsuitable for this method if used with multibyte strings (like UTF-8 strings).

Byte offsets can be converted to character offsets with mb_strlen:

<?php
function char_offset($string, $byte_offset, $encoding = null)
{
$substr = substr($string, 0, $byte_offset);
return
mb_strlen($substr, $encoding ?: mb_internal_encoding());
}
?>
To Top