[ create a new paste ] login | about

Link: http://codepad.org/MzVETYaq    [ raw code | output | fork ]

PHP, pasted on Sep 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

$html = 'This is a quick snippet that often comes in handy: <pre>[code]blah blah[/code]</pre>';

$dom = new DOMDocument;
$dom->loadXML('<customtag>'.$html.'</customtag>');

$xpath = new DOMXPath($dom);
$query = '//pre';
$entries = $xpath->query($query);

foreach($entries as $one){
    $newelement = $dom->createTextNode('Some new node!'); 
    $one->parentNode->replaceChild($newelement, $one);
}

$html = $dom->childNodes->item(0)->nodeValue;

echo $html;


Output:
1
This is a quick snippet that often comes in handy: Some new node!


Create a new paste based on this one


Comments: