- var_dump: documentation ( source)
- preg_replace: documentation ( source)
<?php
$xml = '
<section>
<paragraph>new article test</paragraph>
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal>$nbsp: &nbsp;
$amp;nbsp: &amp;nbsp:
$amp;$nbsp: &amp;&nbsp;
</literal>
</paragraph>
</section>';
$pattern = '(<paragraph[^>]*\>)((?<pre>.*)(?<nb>&nbsp;)(?<post>.*))(<\/paragraph>)';
$newXml = preg_replace( $pattern, '-', $xml );
var_dump( $newXml );