rss reader - encoding?

phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

rss reader - encoding?

Beitrag von phatbyte »

hallo!

hab hier ein problem und zwar - ich verwende den feed http://www.microsoft.com/germany/msdn/rss/aktuell.xml welcher utf8 sein sollte laut firefox - wenn ich den nun anzeigen lasse mittels rss_template.html sind die umlaute kaputt - was mach ich falsch?

danke!
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

ist ne intressante frage...
welche encoding hat denn deine website ?
*** make your own tools (wishlist :: thx)
phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

Beitrag von phatbyte »

wow schnelle antwort :)

iso-8859-1
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Das ist der Haken... ein UTF-8-codierter Feed, dargestellt auf einer Iso-8859-1 - Website, muss zu diversen Problemen bei den Umlauten führen.
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Kleiner Tipp: utf8_decode() bei der Ausgabe benutzen... dann kannst Du deine Seite auch im Iso-8859-1 weiterlaufen lassen!
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

Beitrag von phatbyte »

habs jetzt hier
$sFeedContent = utf8_decode($sFeedContent);

und hier probiert
$tpl->set("d", "DESCRIPTION", utf8_decode(htmlentities($item['description'],ENT_QUOTES)));

müsste doch klappen oder? tuts aber nicht :roll:
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Japp, sieht gut aus... poste doch einfach mal den kompletten Code, dann schauen wir uns das gemeinsam an!
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

Beitrag von phatbyte »

Code: Alles auswählen

<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname   :     Insert RSS feed
* Authors:	  :	    Timo Hummel, Andreas Lindner
* Copyright   :     Contenido - four for business
* Created     :     30.09.2005
************************************************/

cInclude("pear", "XML/Parser.php");
cInclude("pear", "XML/RSS.php");

if ("CMS_VALUE[0]" == "")
{
  $sFeed = "http://www.contenido.org/rss/de/news";
} else {
  $sFeed = "CMS_VALUE[0]";
}

if ("CMS_VALUE[2]" == "")
{
  $FeedMaxItems = 999;
} else {
	$FeedMaxItems = intval("CMS_VALUE[2]");
}

/* Preparse feed for an encoding due to the poorly designed
   PHP XML parser */
$sFeedContent = substr(@file_get_contents($sFeed),0,1024);
$sFeedContent = utf8_decode($sFeedContent);

$regExp = "/<\?xml.*encoding=[\"\'](.*)[\"\']\?>/i";
		
preg_match($regExp,trim($sFeedContent),$matches);

if ($matches[1])
{
  $rss =& new XML_RSS($sFeed, $matches[1]);
} else {
  $rss =& new XML_RSS($sFeed);
}

$rss->parse();

$tpl = new Template;

$i = 0;
foreach ($rss->getItems() as $item)
{
	if ($i < $FeedMaxItems) {
	    $tpl->set("d", "TITLE", htmlentities($item['title'],ENT_QUOTES));
    	$tpl->set("d", "LINK", htmlentities($item['link'],ENT_QUOTES));
    	$tpl->set("d", "DESCRIPTION", utf8_decode(htmlentities($item['description'],ENT_QUOTES)));
    	$tpl->set("d", "READ_ON", mi18n("weiterlesen"));
	    $tpl->next();
	}
	$i++;
}

$tpl->generate($cfgClient[$client]["path"]["frontend"]."templates/"."CMS_VALUE[1]");
?>
vielen dank!
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Für mich sieht der Code korrekt aus.

Ich habe den Microsoft-Feed bei einer Kundenseite eingebaut, die ebenfalls mit ISO-8859-1 codiert ist und was soll ich sagen - es funktioniert. Umlaute werden ordnungsgemäß ausgegeben.

Ich werde aber nochmal bzgl. des Problems grübeln.

Gruss,
Christian
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Poste doch mal bitte die RSS.PHP (XML_RSS-Klasse)

Das hier gibt mir zu denken:

Code: Alles auswählen

$regExp = "/<\?xml.*encoding=[\"\'](.*)[\"\']\?>/i";
      
preg_match($regExp,trim($sFeedContent),$matches);

if ($matches[1])
{
  $rss =& new XML_RSS($sFeed, $matches[1]);
} else {
  $rss =& new XML_RSS($sFeed);
} 
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

Beitrag von phatbyte »

Code: Alles auswählen

<?php
// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP Version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Martin Jansen <mj@php.net>                                  |
// |                                                                      |
// +----------------------------------------------------------------------+
//
// $Id$
//

cInclude("pear", "XML/Parser.php");


/**
* RSS parser class.
*
* This class is a parser for Resource Description Framework (RDF) Site
* Summary (RSS) documents. For more information on RSS see the
* website of the RSS working group (http://www.purl.org/rss/).
*
* @author Martin Jansen <mj@php.net>
* @version $Revision$
* @access  public
*/
class XML_RSS extends XML_Parser
{
    // {{{ properties

    /**
     * @var string
     */
    var $insideTag = '';

    /**
     * @var string
     */
    var $activeTag = '';

    /**
     * @var array
     */
    var $channel = array();

    /**
     * @var array
     */
    var $items = array();

    /**
     * @var array
     */
    var $item = array();

    /**
     * @var array
     */
    var $image = array();

    /**
     * @var array
     */
    var $textinput = array();
    
    /**
     * @var array
     */
    var $textinputs = array();

    /**
     * @var array
     */
    var $parentTags = array('CHANNEL', 'ITEM', 'IMAGE', 'TEXTINPUT');

    /**
     * @var array
     */
    var $channelTags = array('TITLE', 'LINK', 'DESCRIPTION', 'IMAGE',
                              'ITEMS', 'TEXTINPUT');

    /**
     * @var array
     */
    var $itemTags = array('TITLE', 'LINK', 'DESCRIPTION', 'PUBDATE');

    /**
     * @var array
     */
    var $imageTags = array('TITLE', 'URL', 'LINK');

    var $textinputTags = array('TITLE', 'DESCRIPTION', 'NAME', 'LINK');

    /**
     * List of allowed module tags
     *
     * Currently Dublin Core Metadata and the blogChannel RSS module
     * are supported.
     *
     * @var array
     */
    var $moduleTags = array('DC:TITLE', 'DC:CREATOR', 'DC:SUBJECT', 'DC:DESCRIPTION',
                            'DC:PUBLISHER', 'DC:CONTRIBUTOR', 'DC:DATE', 'DC:TYPE',
                            'DC:FORMAT', 'DC:IDENTIFIER', 'DC:SOURCE', 'DC:LANGUAGE',
                            'DC:RELATION', 'DC:COVERAGE', 'DC:RIGHTS',
                            'BLOGCHANNEL:BLOGROLL', 'BLOGCHANNEL:MYSUBSCRIPTIONS',
                            'BLOGCHANNEL:MYSUBSCRIPTIONS', 'BLOGCHANNEL:CHANGES');

    // }}}
    // {{{ Constructor

    /**
     * Constructor
     *
     * @access public
     * @param mixed File pointer or name of the RDF file.
     * @return void
     */
    function XML_RSS($handle = '', $encoding = false)
    {
    	if ($encoding !== false)
    	{
        	$this->XML_Parser($encoding);
    	} else {
    		$this->XML_Parser();	
    	}

        if (@is_resource($handle)) {
            $this->setInput($handle);
        } elseif ($handle != '') {
            $this->setInputFile($handle);
        } else {
            $this->raiseError('No filename passed.');
        }
    }

    // }}}
    // {{{ startHandler()

    /**
     * Start element handler for XML parser
     *
     * @access private
     * @param  object XML parser object
     * @param  string XML element
     * @param  array  Attributes of XML tag
     * @return void
     */
    function startHandler($parser, $element, $attribs)
    {
        switch ($element) {
            case 'CHANNEL':
            case 'ITEM':
            case 'IMAGE':
            case 'TEXTINPUT':
                $this->insideTag = $element;
                break;

            default:
                $this->activeTag = $element;
        }
    }

    // }}}
    // {{{ endHandler()

    /**
     * End element handler for XML parser
     *
     * If the end of <item>, <channel>, <image> or <textinput>
     * is reached, this function updates the structure array
     * $this->struct[] and adds the field "type" to this array,
     * that defines the type of the current field.
     *
     * @access private
     * @param  object XML parser object
     * @param  string
     * @return void
     */
    function endHandler($parser, $element)
    {
        if ($element == $this->insideTag) {
            $this->insideTag = '';
            $this->struct[] = array_merge(array('type' => strtolower($element)),
                                          $this->last);
        }

        if ($element == 'ITEM') {
            $this->items[] = $this->item;
            $this->item = '';
        }

        if ($element == 'IMAGE') {
            $this->images[] = $this->image;
            $this->image = '';
        }

        if ($element == 'TEXTINPUT') {
            $this->textinputs = $this->textinput;
            $this->textinput = '';
        }

        $this->activeTag = '';
    }

    // }}}
    // {{{ cdataHandler()

    /**
     * Handler for character data
     *
     * @access private
     * @param  object XML parser object
     * @param  string CDATA
     * @return void
     */
    function cdataHandler($parser, $cdata)
    {
        if (in_array($this->insideTag, $this->parentTags)) {
            $tagName = strtolower($this->insideTag);
            $var = $this->{$tagName . 'Tags'};

            if (in_array($this->activeTag, $var) ||
                in_array($this->activeTag, $this->moduleTags)) {
                $this->_add($tagName, strtolower($this->activeTag),
                            $cdata);
            }
            
        }
    }

    // }}}
    // {{{ defaultHandler()

    /**
     * Default handler for XML parser
     *
     * @access private
     * @param  object XML parser object
     * @param  string CDATA
     * @return void
     */
    function defaultHandler($parser, $cdata)
    {
        return;
    }

    // }}}
    // {{{ _add()

    /**
     * Add element to internal result sets
     *
     * @access private
     * @param  string Name of the result set
     * @param  string Fieldname
     * @param  string Value
     * @return void
     * @see    cdataHandler
     */
    function _add($type, $field, $value)
    {
        if (empty($this->{$type}) || empty($this->{$type}[$field])) {
            $this->{$type}[$field] = $value;
        } else {
            $this->{$type}[$field] .= $value;
        }

        $this->last = $this->{$type};
    }

    // }}}
    // {{{ getStructure()

    /**
     * Get complete structure of RSS file
     *
     * @access public
     * @return array
     */
    function getStructure()
    {
        return (array)$this->struct;
    }

    // }}}
    // {{{ getchannelInfo()

    /**
     * Get general information about current channel
     *
     * This function returns an array containing the information
     * that has been extracted from the <channel>-tag while parsing
     * the RSS file.
     *
     * @access public
     * @return array
     */
    function getChannelInfo()
    {
        return (array)$this->channel;
    }

    // }}}
    // {{{ getItems()

    /**
     * Get items from RSS file
     *
     * This function returns an array containing the set of items
     * that are provided by the RSS file.
     *
     * @access public
     * @return array
     */
    function getItems()
    {
        return (array)$this->items;
    }

    // }}}
    // {{{ getImages()

    /**
     * Get images from RSS file
     *
     * This function returns an array containing the set of images
     * that are provided by the RSS file.
     *
     * @access public
     * @return array
     */
    function getImages()
    {
        return (array)$this->images;
    }

    // }}}
    // {{{ getTextinputs()

    /**
     * Get text input fields from RSS file
     *
     * @access public
     * @return array
     */
    function getTextinputs()
    {
        return (array)$this->textinputs;
    }

    // }}}

}
?>
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Ersetze mal testhalber diesen Code

Code: Alles auswählen

$regExp = "/<\?xml.*encoding=[\"\'](.*)[\"\']\?>/i";
     
preg_match($regExp,trim($sFeedContent),$matches);

if ($matches[1])
{
  $rss =& new XML_RSS($sFeed, $matches[1]);
} else {
  $rss =& new XML_RSS($sFeed);
}
mit diesem

Code: Alles auswählen

$rss =& new XML_RSS($sFeed, "UTF-8");
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

Beitrag von phatbyte »

geht nicht
Dalamar
Beiträge: 298
Registriert: Di 16. Nov 2004, 15:43
Wohnort: Arnstadt / Thüringen
Kontaktdaten:

Beitrag von Dalamar »

Sehr merkwürdig... probiere Spassenshalber mal

Code: Alles auswählen

$rss =& new XML_RSS($sFeed, "ISO-8859-1");
Und poste mal bitte was anstatt der Umlaute bei Dir herauskommt !

Gruss,
Christian
Beruflich: eComradeGroup und Media Atoll
Privat: Fantasybuch.net ;)
phatbyte
Beiträge: 95
Registriert: Mi 2. Nov 2005, 14:05
Wohnort: Austria
Kontaktdaten:

Beitrag von phatbyte »

Krass es funktioniert :D Vielen Vielen Vielen Dank!!
Gesperrt