开发者

PHP error in doing xml parsing?

i am working in php. I want to create xml of resul of query.

I my query result i am getting a number of URLs. When i want to create xml file of these urls a problem开发者_开发问答 has occured due to spaces and some special characters in url.

If i try same thing for a url which does not has any space in url than no problem is occured.

This is my php program:-

$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>"); 

These type of entries in url creating problem :-"http://192.168.1.214/MusicApplication/Songs/RUFF BEAT - Baby_Justin Bieber_DJs Sunny & Puneet(VT).mp3"

Note:-please see the file name.

Please suggest me what should i do to solve this type of problem.


You should probably escape the file name by replacing spaces with %20. Or just use urlencode() on the file name.

Also, please escape row contents with htmlspecialchars or you may end up with invalid XML.


This is the solution for my problem... echo ("".htmlentities($row[$i]). "");

means we should pass data from htmlentities() . by using this function we can convert special characters into html characters.

Thank you all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜