469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Cannot change encoding at a XML with php

mikek12004
200 100+
I have an xml written in a file. I want in the 1st line
<code>
<?xml version="1.0" encoding="iso-88-59-7"?>
</code>
to change the encoding to utf-8 any easy way to do that?
Nov 11 '08 #1
5 2903
Dormilich
8,651 Expert Mod 8TB
code tag is [code] not <code> or use the button with the "#" symbol

the solution depends on which language you want to use for that (possibilities: any (server) scripting lanuage (C, Java, PHP, ASP, Perl,...), even XSLT)

regards
Nov 11 '08 #2
mikek12004
200 100+
I have this XML
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-7"?>
  2. <asx version="3.0" >
  3. <title>General Music ASX playlist</title>
  4. <moreinfo href="http://www.generalmusic.com"/>
  5.  
  6. <entry>
  7. <title>8.07409|1.00922|ΚΡΑΤΗΣΕ ΜΕ ΣΤΟ ΡΥΘΜΟ|9.00402||8.00|</title>
  8. <ref href="UserFiles/songs/03/8.07409.mp3" />
  9. <param name="image" value="UserFiles/Image/1.00922.jpg" />
  10. </entry>
  11. <entry>
  12. <title>8.07410|1.00922|ΚΡΑΤΗΣΕ ΜΕ ΣΤΟ ΡΥΘΜΟ|9.00402||8.00|</title>
  13. <ref href="UserFiles/songs/03/8.07410.mp3" />
  14. <param name="image" value="UserFiles/Image/1.00922.jpg" />
  15. </entry>
  16. </asx>
  17.  
and I want to change the encoding to utf-8 when I download it and by hand change the encoding,save it and upload it all is good.
I created a php script to automate the process which is here
Expand|Select|Wrap|Line Numbers
  1. $id=$_SESSION['id'];
  2.  
  3.     $file = fopen("../player/".$id.".xml","r");
  4.     $msg=fread($file,filesize("../player/".$id.".xml"));
  5.     fclose($file);
  6.  
  7.     //$msg=str_replace("iso-8859-7","utf-8",$msg);
  8.     $file = fopen("../player/".$id.".xml","w");
  9.     fwrite($file,$msg);
  10.     fclose($file);
  11.  
but then all the greeks in the xml (those in the title tag) gets destroyed any help on how can I do that?
Nov 11 '08 #3
Dormilich
8,651 Expert Mod 8TB
I think you have to actually encode the content to utf-8. use utf8_encode().

regards
Nov 11 '08 #4
mikek12004
200 100+
OK found it before writing to the file I used iconv to change the string to utf-8
Thanks for your time!
Nov 11 '08 #5
Dormilich
8,651 Expert Mod 8TB
never mind. I'm glad I could help.
Nov 11 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Ann | last post: by
1 post views Thread by Alexander Cohen | last post: by
1 post views Thread by Jason Chan | last post: by
4 posts views Thread by jcsnippets.atspace.com | last post: by
3 posts views Thread by TomislaW | last post: by
3 posts views Thread by Diego F. | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.