PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 27th, 2005, 09:45 PM
alfred.baudisch alfred.baudisch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 alfred.baudisch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 7 sec
Reputation Power: 0
Problems with enconding after reading XML files

Hello,

I'm trying to print a XML Report to HTML. Ok, I have used
- SimpleXML
- PEAR::XML_Parser

and both worked perfect. But in both, all characters with accents are printed wrong. Ex: á is printed á
ê is printed ê and so on..
And this is a very grave problem to me, because the most part of our words have accents.

The strange thing is: if the report has only a few lines, like 50, it prints normal. But the question is that the most part of the reports have more than 40.000 lines and this enconding problem occurs.

My XML file is correctly encoded:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>


What should I do?
I really need this. Any help will be very appreciated.
Thanks.
Alfred

Here is an example of the code I'm using:
PHP Code:
<?php 
 
// Load Report
$xml simplexml_load_string(file_get_contents('Report_89  701247.xml'));
 
$Last false;
 
foreach(
$xml->event as $event)
{
    
// Get date
    
$Date date('d/m/Y'$event->time);
 
    
// If is new date, print it on top and a hr
    
if($Date != $Last)
    {
        echo 
'<hr color=black size=1><B>' $Date '</B><BR/><BR>';
    }
 
    
// Different event, different color
    
if($event->incoming == 'Yes')
    {
        echo 
'<font color=#800000>';
    }
 
    
// The day report
    
echo '- ' $event->text '<BR>';
 
    
// Close color
    
if($event->incoming == 'Yes')
    {
        echo 
'</font>';
    }
 
    
$Last $Date;
}
 
?>

Reply With Quote
  #2  
Old February 27th, 2005, 10:04 PM
alfred.baudisch alfred.baudisch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 alfred.baudisch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 7 sec
Reputation Power: 0
I have solved my problem. I have found the PHP Function utf8_decode and changed line:
PHP Code:
<?php
// BEFORE
echo '- ' $event->text '<BR>';
 
// NOW IT IS:
echo '- ' utf8_decode(utf8_decode($event->text)) . '<BR>';
?>


It is necessary to call utf8_decode two times, because it oddly prints 2 encoded characters for each accent.

Cya
Alfred

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Problems with enconding after reading XML files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway