0

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.

Jonnix
  • 4,121
  • 1
  • 30
  • 31
Pushpendra Kuntal
  • 6,118
  • 20
  • 69
  • 119
  • *(related)* [A simple program to CRUD node and node values of xml file](http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of-xml-file) – Gordon Sep 13 '11 at 10:34
  • PHP has a good bunch of built-in libraries to create XML. There's not need to handle manually all the subtleties of the XML syntax. You can use, for instance, [XMLWriter](http://php.net/XMLWriter). – Álvaro González Sep 13 '11 at 10:40

2 Answers2

1

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.

Victor Vasiliev
  • 462
  • 2
  • 12
0

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.

Pushpendra Kuntal
  • 6,118
  • 20
  • 69
  • 119