PHP 8.4.0 RC4 available for testing

DOMElement::insertAdjacentText

(PHP 8 >= 8.3.0)

DOMElement::insertAdjacentTextInsert adjacent text

Descripción

public DOMElement::insertAdjacentText(string $where, string $data): void

Inserts text at a relative position given by where.

Parámetros

where

  • beforebegin - Insert before the target element.
  • afterbegin - Insert as the first child of the target element.
  • beforeend - Insert as the last child of the target element.
  • afterend - Insert after the target element.

data

The string to insert.

Valores devueltos

No devuelve ningún valor.

Ejemplos

Ejemplo #1 DOMElement::insertAdjacentText() example

<?php

$dom
= new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><container><p>H</p></container>');

$container = $dom->documentElement;
$p = $container->firstElementChild;

$p->insertAdjacentText("afterbegin", "P");
$p->insertAdjacentText("beforeend", "P");

echo
$dom->saveXML();
?>

El resultado del ejemplo sería:

<?xml version="1.0"?>
<container><p>PHP</p></container>

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top