我想通過我的MySQL數據進行循環,併爲我的XML清理它,但我試圖以最有效的方式執行此操作。以下是我的代碼到目前爲止。此代碼僅清理一個字段CompanyName
如果可能,我想清除所有8個字段(如果相同的循環)。清潔XML的XML數據
header("Content-type: text/xml");
$SQL_query = "SELECT * FROM COMPANYINFO ORDER BY CompanyName DESC";
$resultID = mysql_query($SQL_query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<markers>\n"; w
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
// Escaping illegal characters
$row['CompanyName'] = str_replace("&", "&", $row['CompanyName']);
$row['CompanyName'] = str_replace("<", "<", $row['CompanyName']);
$row['CompanyName'] = str_replace(">", ">", $row['CompanyName']);
$row['CompanyName'] = str_replace("\"", """, $row['CompanyName']);
$xml_output .= "\t\t<marker name='.$row['CompanyName']."' address='".$row['Address_1']."' phone='".$row['Phone']."' lat='".$row['Lat_Info']."' lng='".$row['Long_Info']."' county='".$row['County']."'/>\n";
}
$xml_output .= "</markers>";
echo $xml_output;
感謝您的信息是非常有益的。我不應該用特殊字符替換「&」嗎?我注意到帶有amperstands的字段仍然在拋出一個錯誤。 – Denoteone
它逃脫了我:http://codepad.org/sfMR0JTn – SomeKittens