Cannot change encoding at a XML with php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikek12004
    New Member
    • Sep 2008
    • 200

    #1

    Cannot change encoding at a XML with php

    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?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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

    Comment

    • mikek12004
      New Member
      • Sep 2008
      • 200

      #3
      Cannot change encoding at a XML with php

      I have this XML
      Code:
      <?xml version="1.0" encoding="iso-8859-7"?>
      <asx version="3.0" >
      <title>General Music ASX playlist</title>
      <moreinfo href="http://www.generalmusic.com"/>
      
      <entry>
      <title>8.07409|1.00922|ΚΡΑΤΗΣΕ ΜΕ ΣΤΟ ΡΥΘΜΟ|9.00402||8.00|</title>
      <ref href="UserFiles/songs/03/8.07409.mp3" />
      <param name="image" value="UserFiles/Image/1.00922.jpg" />
      </entry>
      <entry>
      <title>8.07410|1.00922|ΚΡΑΤΗΣΕ ΜΕ ΣΤΟ ΡΥΘΜΟ|9.00402||8.00|</title>
      <ref href="UserFiles/songs/03/8.07410.mp3" />
      <param name="image" value="UserFiles/Image/1.00922.jpg" />
      </entry>
      </asx>
      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
      Code:
      $id=$_SESSION['id'];
      
      	$file = fopen("../player/".$id.".xml","r");
      	$msg=fread($file,filesize("../player/".$id.".xml"));
      	fclose($file);
      	
      	//$msg=str_replace("iso-8859-7","utf-8",$msg);
      	$file = fopen("../player/".$id.".xml","w");
      	fwrite($file,$msg);
      	fclose($file);
      but then all the greeks in the xml (those in the title tag) gets destroyed any help on how can I do that?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I think you have to actually encode the content to utf-8. use utf8_encode().

        regards

        Comment

        • mikek12004
          New Member
          • Sep 2008
          • 200

          #5
          OK found it before writing to the file I used iconv to change the string to utf-8
          Thanks for your time!

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            never mind. I'm glad I could help.

            Comment

            Working...