- htmlentities: documentation ( source)
- str_replace: documentation ( source)
<?php
$_POST['contentDetails'] = '<p>This is data sample. </p><p>Second part of the paragraph. </p>';
$xml = '<?xml version="1.0" encoding="UTF-8">';
$xml .= '<root>';
$xml .= '<myData>';
$xml .= '<content>' . htmlentities(str_replace(" ", "", $_POST['contentDetails'])) . '</content>';
$xml .= '</myData>';
$xml .= '</root>';
echo $xml;