【问题标题】:PHP error in doing xml parsing?做 xml 解析时的 PHP 错误?
【发布时间】:2011-09-13 10:28:41
【问题描述】:

我正在使用 php。我想创建查询结果的xml。

我的查询结果我得到了一些 URL。当我想创建这些 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”

注意:-请看文件名。

请建议我该怎么做才能解决此类问题。

【问题讨论】:

标签: php


【解决方案1】:

您可能应该通过用 %20 替换空格来转义文件名。或者只是在文件名上使用 urlencode()。

另外,请使用 htmlspecialchars 转义行内容,否则您可能会得到无效的 XML。

【讨论】:

  • 那么请告诉我使用代码转换此空间 %20 等的过程。
【解决方案2】:

这是我的问题的解决方案... echo ("".htmlentities($row[$i])."");

意味着我们应该从 htmlentities() 传递数据。通过这个函数我们可以将特殊字符转换成html字符。

谢谢大家。

【讨论】:

    猜你喜欢
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    相关资源
    最近更新 更多