How I can convert this line :
<user_profil><username>root</username><email>[email protected]</email></user_profil>
into something formatted like :
<user_profil>
<username>root</username>
<email>[email protected]</email>
</user_profil>
using regex.
Also I dont understand why $doc->saveHTML()
(an instance of DOMDocument) return the result as one line only.
Actually using regex would be the longer option. Rather use
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$xml_string = $doc->saveXML();
echo $xml_string;
This should get you the formatted code.
Using @georoot way is better, but if you want to try regex, you can do it this way:
(\s+)(\<\w+\>)(\<\w+\>\w+\<\/\w+\>)(\<\w+\>[\w\@\.]+\<\/\w+\>)(\<\/\w+\>)
Replace with:
$2\n\t$3\n\t$4\n$5
Demo: https://regex101.com/r/QtVCoY/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With