PHP file convert to XML

<?
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&apos;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return
$xmlStr;
}

// Start XML file, echo parent node
echo '<items>';

echo '<item ';
echo
'name="' . parseToXML(stripslashes($sName)) . '" ';
echo
'address="' . parseToXML(stripslashes($sAddress)) . '" ';
echo
'price="' . parseToXML($iPrice) . '" ';
echo
'link="' . parseToXML($sLink) . '" ';
echo
'details="' . parseToXML(stripslashes($tDetails)) . '" ';
echo
'other="' . parseToXML(stripslashes($sOther)) . '" ';
echo
'/>';

// End XML file
echo '</items>';

?>

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.