Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
andrej
Hangin' Around



Joined: Sep 10, 2005
Posts: 48

PostPosted: Sat May 20, 2006 7:53 am Reply with quote

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-Cool

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:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
^

My question is whether there is any possibilty to make this work ?

Thanks, guys !
 
View user's profile Send private message
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Sat May 20, 2006 3:43 pm Reply with quote

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.
 
View user's profile Send private message Send e-mail
andrej







PostPosted: Sat May 20, 2006 5:34 pm Reply with quote

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
 
Guardian2003







PostPosted: Sat May 20, 2006 6:29 pm Reply with quote

You may want to look at this [ Only registered users can see links on this board! Get registered or login! ]
 
andrej







PostPosted: Sat May 20, 2006 6:31 pm Reply with quote

OK. I have managed to look through php.net manual a bit and realise what foolish mistakes i have made Embarassed .

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..
 
Guardian2003







PostPosted: Sat May 20, 2006 8:27 pm Reply with quote

Thanks for letting us know you are now working - great job!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©