2012-12-03 35 views
0

我想從表中檢索XML標記。 我無法打印標籤,只有值。從SQL表檢索XML標記與PHP

例如:

<product> 
<item>a</item> 
<price>20</price> 
</product> 

當我嘗試用PHP代碼打印:

$q2 = mysql_query("SELECT * from products"); 
while ($rowq2 = mysql_fetch_array($q2)) { 
echo $rowq2["product_xml"]; 
} 

打印是沒有標籤的,但我想打印這個,因爲它是(有標籤)。

請幫幫我!

+0

你檢查過視圖/頁面的源代碼?您的瀏覽器可能會解釋它們,這是它們不可見的原因。 – diggersworld

回答

0

這是因爲瀏覽器認爲<product>是一個HTML標記並且不顯示它。 您需要使用htmlentities()這樣的:

$q2 = mysql_query("SELECT * from products"); 
while ($rowq2 = mysql_fetch_array($q2)) { 
    echo htmlentities($rowq2["product_xml"]); 
}