eval.in

Paste #10046

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<?php

$template = '<is:namespace:tag attr="value">foo<is:namespace:tag attr="value" /></is:namespace:tag>';

$fixed = preg_replace('((</?)is:namespace(:[a-z]+))', '$1ns1$2', $template);

$fixed = "<root xmlns:ns1='is:namespace'>$fixed</root>";

$parser = simplexml_load_string($fixed);

echo $parser->asXML();

Program Output

<?xml version="1.0"?>
<root xmlns:ns1="is:namespace"><ns1:tag attr="value">foo<ns1:tag attr="value"/></ns1:tag></root>

OK (0.008 sec real, 0.010 sec wall, 13 MB, 43 syscalls)

Fork