Author |
Message |
andrej
Hangin' Around
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Sep 10, 2005
Posts: 48
|
Posted:
Sat May 20, 2006 7:53 am |
|
Hello !
I would like to change an RSS script encoding from iso-8859-2 to UTF-8, so it's rendered proprely within phpnuke portal ( which is also UTF-
Looking at php.net tutorials, i came up with a small script, which according to my fairly limited knowledge of php should work..
Code:<?php
$lines = file('http://www.rtvslo.si/feeds/00.xml');
$feed=fopen("test.xml","w");
foreach ($lines as $line_num => $line) {
$line= str_replace("encoding=\"iso-8859-2\"", "encoding=\"UTF-8\"", $line);
echo "". htmlspecialchars($line) . "<br />\n";
fprintf($feed, "" . htmlspecialchars($line) . "<br />\n");
}
fclose($feed);
?>
|
After trying to open test.xml i see this..
XML Parsing Error: not well-formed
Line Number 1, Column 1:<?xml version="1.0" encoding="UTF-8"?>
^
My question is whether there is any possibilty to make this work ?
Thanks, guys ! |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Guardian2003
Site Admin
![](modules/Forums/images/avatars/125904890252d880f79f312.png)
Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Sat May 20, 2006 3:43 pm |
|
I am not sure it is possible to change the encoding 'on the fly'. I think you would have to first decode to the original encoding and either store it temporarily as a temp file or data construct like a $variable and use that as the base for the new encoding to re-encode it.
Or find out what the exact character differences are between the two and write something to work with that. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
andrej
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat May 20, 2006 5:34 pm |
|
Well, what i am trying to do here is read from the encoding..
change the header ( and if required all other necessary characters ) and then save it as some other file..
The thing is when i attempt to save it to another file, which would be then the modified feed phpnuke would use, but i keep on getting this error.. xml feed is not well formatted.... I am wondering why this keeps on happening... and also
whether this "export" method can be actually modified so it does what i want it to ?
thanks for your replies |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Guardian2003
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat May 20, 2006 6:29 pm |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
andrej
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat May 20, 2006 6:31 pm |
|
OK. I have managed to look through php.net manual a bit and realise what foolish mistakes i have made .
It works OK now..
I just decided to post the code i used. I might be of some use to someone..
Code:<?php
// open the RSS feed you wish to use
$lines = file('http://www.rtvslo.si/feeds/00.xml');
//file, where the new RSS will be..
$feed=fopen("test.xml","w");
foreach ($lines as $line_num => $line) {
// replace all the characters with the appropriate ones
$line= str_replace("encoding=\"iso-8859-2\"", "encoding=\"UTF-8\"", $line);
$line= str_replace("ľ", "ž", $line);
$line= str_replace("ą", "š", $line);
$line= str_replace("č", "č", $line);
$line= str_replace("©", "Š", $line);
$line= str_replace("®", "Ž", $line);
//outputs to the file
fprintf($feed, "%s", $line);
}
fclose($feed);
?>
|
Thanks again for snappy response.. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Guardian2003
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat May 20, 2006 8:27 pm |
|
Thanks for letting us know you are now working - great job! |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|