[英]PHP error in doing xml parsing?
我正在用PHP工作。 我想創建查詢結果的xml。
我的查詢結果中有許多網址。 當我想創建這些URL的xml文件時,由於空格和URL中的一些特殊字符而發生了問題。
如果我為URL中沒有空格的URL嘗試相同的事情,則不會發生任何問題。
這是我的php程序:
$rs = mysql_query("SELECT urlofsong FROM music ORDER BY date DESC LIMIT 0,10") or die ("invalid query");
//count the no. of columns in the table
$fcount = mysql_num_fields($rs);
//you can choose any name for the starting tag
//echo "$pass";
echo ("<result>");
while($row = mysql_fetch_array( $rs ) )
{
echo ("<tablerow>");
for($i=0; $i< $fcount; $i++)
{
$tag = mysql_field_name( $rs, $i );
echo ("<$tag>". $row[$i]. "</$tag>");
}
echo ("</tablerow>");
}
echo ("</result>");
這些類型的條目會在url中產生問題:-“ http://192.168.1.214/MusicApplication/Songs/RUFF BEAT-Baby_Justin Bieber_DJs Sunny&Puneet(VT).mp3”
注意:-請參閱文件名。
請建議我該怎么做才能解決此類問題。
您可能應該通過用%20替換空格來轉義文件名。 或者只是在文件名上使用urlencode()。
另外,請使用htmlspecialchars轉義行內容,否則可能會得到無效的XML。
這是解決我的問題的方法... echo(“” .htmlentities($ row [$ i])。“”);
意味着我們應該從htmlentities()傳遞數據。 通過使用此功能,我們可以將特殊字符轉換為html字符。
謝謝你們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.