I have a function that generates XML from a source. It works perfectly however, when certain fields are long. It stretches the table to the right and ruins the formatting of the website. Is there a way to maybe insert line breaks after a certain amount of text or keep it within the table space?
The function for the code is:
function generateXML($mlsID, $xmlLocation) {
if (file_exists($xmlLocation)) {
$simpleXMLobject = simplexml_load_file($xmlLocation);
if (!$simpleXMLobject) {
echo 'ERROR: unable to parse XML file';
exit;
}
$mlsIdWasLocatedInXMLfile = false;
foreach ($simpleXMLobject->Listing as $listing) {
if ($listing->ListingDetails->MlsId == $mlsID) {
$mlsIdWasLocatedInXMLfile = true;
//echo '<table width ="500" style="table-layout:fixed" >';
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($listing->asXML());
echo("<pre>" . htmlspecialchars($dom->saveXML()) . "</pre>");
//echo '</table>';
}
}
if ($mlsIdWasLocatedInXMLfile === false) {
echo "MLS ID NOT FOUND IN XML FILE";
}
} else {
echo 'ERROR: file not found';
}
}
Well you should not format the output, as it would make no sense sometimes. Better change your website – make element, in which you show your information scrollable.
If you need to do word wrapping, try using this function: wordwrap