Foros del Web » Programando para Internet » PHP »

carácteres raros al cargar archivo xml en php

Estas en el tema de carácteres raros al cargar archivo xml en php en el foro de PHP en Foros del Web. Hola buenas, Tengo este script php que al mostrar el xml en php no me muestra los acentos etc etc y me muestra caracteres raros. ...
  #1 (permalink)  
Antiguo 21/10/2009, 00:33
Avatar de syntex  
Fecha de Ingreso: noviembre-2002
Ubicación: Cataluña
Mensajes: 978
Antigüedad: 21 años, 5 meses
Puntos: 4
carácteres raros al cargar archivo xml en php

Hola buenas,

Tengo este script php que al mostrar el xml en php no me muestra los acentos etc etc y me muestra caracteres raros.

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<?
$url_rss 
"http://www.noticias.com/frss/economia.rss";
$url $url_rss;
$cant_rss 15;
?>
<?php
$RSS_Content 
= array();

function 
RSS_Tags($item$type)
{
        
$y = array();
        
$tnl $item->getElementsByTagName("title");
        
$tnl $tnl->item(0);
        
$title $tnl->firstChild->data;

        
$tnl $item->getElementsByTagName("link");
        
$tnl $tnl->item(0);
        
$link $tnl->firstChild->data;

        
$tnl $item->getElementsByTagName("description");
        
$tnl $tnl->item(0);
        
$description $tnl->firstChild->data;

        
$y["title"] = $title;
        
$y["link"] = $link;
        
$y["description"] = $description;
        
$y["type"] = $type;
        
        return 
$y;
}


function 
RSS_Channel($channel)
{
    global 
$RSS_Content;

    
$items $channel->getElementsByTagName("item");
    
    
// Processing channel
    
    
$y RSS_Tags($channel0);        // get description of channel, type 0
    
array_push($RSS_Content$y);
    
    
// Processing articles
    
    
foreach($items as $item)
    {
        
$y RSS_Tags($item1);    // get description of article, type 1
        
array_push($RSS_Content$y);
    }
}

function 
RSS_Retrieve($url)
{
    global 
$RSS_Content;

    
$doc  = new DOMDocument();
    
$doc->load($url);

    
$channels $doc->getElementsByTagName("channel");
    
    
$RSS_Content = array();
    
    foreach(
$channels as $channel)
    {
         
RSS_Channel($channel);
    }
    
}


function 
RSS_RetrieveLinks($url)
{
    global 
$RSS_Content;

    
$doc  = new DOMDocument();
    
$doc->load($url);

    
$channels $doc->getElementsByTagName("channel");
    
    
$RSS_Content = array();
    
    foreach(
$channels as $channel)
    {
        
$items $channel->getElementsByTagName("item");
        foreach(
$items as $item)
        {
            
$y RSS_Tags($item1);    // get description of article, type 1
            
array_push($RSS_Content$y);
        }
         
    }

}


function 
RSS_Links($url$size)
{
    global 
$RSS_Content;

    
$page "<ul>";

    
RSS_RetrieveLinks($url);
    if(
$size 0)
        
$recents array_slice($RSS_Content0$size);

    foreach(
$recents as $article)
    {
        
$type $article["type"];
        if(
$type == 0) continue;
        
$title $article["title"];
        
$link $article["link"];
        
$page .= "<li><a href=\"$link\">$title</a></li>\n";            
    }

    
$page .="</ul>\n";

    return 
$page;
    
}



function 
RSS_Display($url$size)
{
    global 
$RSS_Content;

    
$opened false;
    
$page "";

    
RSS_Retrieve($url);
    if(
$size 0)
        
$recents array_slice($RSS_Content0$size);

    foreach(
$recents as $article)
    {
        
$type $article["type"];
        if(
$type == 0)
        {
            if(
$opened == true)
            {
                
$page .="</ul>\n";
                
$opened false;
            }
            
$page .="<b>";
        }
        else
        {
            if(
$opened == false
            {
                
$page .= "<ul>\n";
                
$opened true;
            }
        }
        
$title $article["title"];
        
$link $article["link"];
        
$description $article["description"];
        
$page .= "<li><a href=\"$link\">$title</a>";
        if(
$description != false)
        {
            
$page .= "<br>$description";
        }
        
$page .= "</li>\n";            
        
        if(
$type==0)
        {
            
$page .="</b><br />";
        }

    }

    if(
$opened == true)
    {    
        
$page .="</ul>\n";
    }
    return 
$page."\n";
    
}


?>
<?php
    
require_once("../funciones/rsslib.php");
    echo 
RSS_Display($url$cant_rss);
?>

</body>
</html>
Muchas gracias.
__________________
------------------------------------------------
La paciencia es el rey de la ciencia
------------------------------------------------

  #2 (permalink)  
Antiguo 21/10/2009, 00:38
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: carácteres raros al cargar archivo xml en php

has probado por cambiar el charset de tu <meta/> a UTF-8 ???
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 21/10/2009, 01:24
Avatar de syntex  
Fecha de Ingreso: noviembre-2002
Ubicación: Cataluña
Mensajes: 978
Antigüedad: 21 años, 5 meses
Puntos: 4
Respuesta: carácteres raros al cargar archivo xml en php

Si lo mismo.
__________________
------------------------------------------------
La paciencia es el rey de la ciencia
------------------------------------------------

Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:27.