CakeFest 2024: The Official CakePHP Conference

DOMText::splitText

(PHP 5, PHP 7, PHP 8)

DOMText::splitTextDüğümü belirtilen konumda iki düğüme böler

Açıklama

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

Düğümü offset ile belirtilen konuma göre iki düğüme böler ve iki düğümü kardeş düğümler haline getirir.

Bölünme sonrası, düğüm offset konumuna kadar olan parçayı içerir. Düğümün bir ebeveyni varsa yeni düğüm, sonraki kardeş düğüm olarak eklenir. Eğer offset düğümün uzunluğuna eşitse kardeş düğüm boş olur.

Bağımsız Değişkenler

offset

Bölme yeri. İlk konum 0'dır.

Dönen Değerler

offset konumundan sonraki parçayı içeren yeni bir düğüm döner.

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