Answer the question
In order to leave comments, you need to log in
How to return HTML instead of a text node?
Hello!
I have the word 'World' (a text node) received via xpath.
Through preg_split
I split it one letter at a time into an array.
How do I now wrap each letter in <span>
and return the result back to '$dom' ?
Example:
- was: <h1>Мир</h1>
- became:
<h1><span>М</span><span>и</span><span>р</span></h1>
$html = '<h1>Мир</h1>';
$dom = new DomDocument();
@$dom->loadHTML( $html );
$xpath = new DomXPath( $dom );
$text_node = $xpath->query( '//h1/text()' )[0];
$chars_arr = preg_split( '//u', $text_node->nodeValue );
foreach ( $chars_arr as $char ) {
// как здесь обернуть каждую букву в '<span>'
// и вернуть результат обратно в $dom вместо текстовой ноды '$text_node'?
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question