Pushpendra Kuntal
Pushpendra Kuntal

Reputation: 6196

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.

Upvotes: 0

Views: 54

Answers (2)

Pushpendra Kuntal
Pushpendra Kuntal

Reputation: 6196

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.

Upvotes: 0

Victor Vasiliev
Victor Vasiliev

Reputation: 462

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.

Upvotes: 1

Related Questions