CakeFest 2024: The Official CakePHP Conference

DOMText::splitText

(PHP 5, PHP 7, PHP 8)

DOMText::splitText Rompe este nodo en dos nodos en el índice especificado

Descripción

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

Rompe este nodo en dos nodos en el índice especificado por offset, manteniéndolos en el árbol como hermanos.

Después de la separación, este nodo contendrá todos el contenido hata offset. Si el nodo original tenía un nodo padre, el nuevo nodo se inserta como el hermano siguiente del nodo original. Cuando offset es igual a la longitud de este nodo, el nuevo nodo no tendrá información.

Parámetros

offset

El índice en el que se hace la separación, comenzando en 0.

Valores devueltos

El nuevo nodo del mismo tipo, que contiene todo el contenido desde y después de 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