note 120064 added to class.domtext
| From: | Trititaty | Date: | Thu, 20 Oct 2016 11:47:47 +0000 |
| Subject: | note 120064 added to class.domtext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206927@lists.php.net to get a copy of this message | ||
Text replacement function for DOM.
<?php
function domTextReplace( $search, $replace, DOMNode &$domNode, $isRegEx = false ) {
if ( $domNode->hasChildNodes() ) {
$children = array();
// since looping through a DOM being modified is a bad idea we prepare an array:
foreach ( $domNode->childNodes as $child ) {
$children[] = $child;
}
foreach ( $children as $child ) {
if ( $child->nodeType === XML_TEXT_NODE ) {
$oldText = $child->wholeText;
if ( $isRegEx ) {
$newText = preg_replace( $search, $replace, $oldText );
} else {
$newText = str_replace( $search, $replace, $oldText );
}
$newTextNode = $domNode->ownerDocument->createTextNode( $newText );
$domNode->replaceChild( $newTextNode, $child );
} else {
domTextReplace( $search, $replace, $child, $isRegEx );
}
}
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 217.74.47.6
----
Manual Page -- http://php.net/manual/en/class.domtext.php
Edit -- https://master.php.net/note/edit/120064
Del: integrated -- https://master.php.net/note/delete/120064/integrated
Del: useless -- https://master.php.net/note/delete/120064/useless
Del: bad code -- https://master.php.net/note/delete/120064/bad+code
Del: spam -- https://master.php.net/note/delete/120064/spam
Del: non-english -- https://master.php.net/note/delete/120064/non-english
Del: in docs -- https://master.php.net/note/delete/120064/in+docs
Del: other reasons-- https://master.php.net/note/delete/120064
Reject -- https://master.php.net/note/reject/120064
Search -- https://master.php.net/manage/user-notes.php