Friday 14 October 2016

Remove new line or space between tags in xml

<?php
$xml = '<Pages>
<Page Name="test">
<controls><test>this is a test.</test></controls>
</Page>
<page Name="User">
<controls><name>Sunil</name></controls>
</page>
</Pages>';
echo $xml;


$re = '/(?<=\>)(\r?\n)|(\r?\n)(?=\<\/)/';
$substring = '';

$xml = preg_replace($re, $substring, $xml);

echo "The result of the substitution is ".$xml;
?>