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.

2

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

then please help me by telling the procedure to convert this space %20 etc using code.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.