0

we are working on a project, in which we need to appendChild and ReplaceChild within the PHP DOM, and then save the file.

PHP Code

<?php 
$string = '<u>technical/u>';
?>
<html><head></head>
<body>
<div>Stack Overflow is great website for technical professionals.
<p>checking all of the websites</p>
</div>
<h1>Looking something new for a technical professional</h1>
</body>
</html>

we just want to replace $string with duplicated words like "technical" is used in and .

The final HTML code will be

<html><head></head>
<body>
<div>Stack Overflow is great website for <u>technical</u> professionals.
<p>checking all of the websites</p>
</div>
<h1>Looking something new for a <u>technical</u> professional</h1>
</body>
</html>
hakre
  • 193,403
  • 52
  • 435
  • 836
Sam
  • 53
  • 1
  • 2
  • 9
  • i have tried , ` $node = $doc->createElement("para", "as fasd fasd fadsf"); $nodename->appendChild($node);echo $nodename->nodeValue."
    "`
    – Sam Sep 28 '12 at 08:28
  • You need to split textnodes for this. These operations are not straight forward trivial, but example code does exist here on stackoverflow. One related I know is [Wordwrap / Cut Text in HTML string](http://stackoverflow.com/q/8482339/367456) another one is [Ignore html tags in preg_replace](http://stackoverflow.com/q/8193327/367456) which - despite the title - shows how to do that with `DOMDocument` and `DOMText`. – hakre Jun 23 '13 at 20:49

0 Answers0