Jump to content

[SOLVED] RSS, having problem with the text


Tiltan

Recommended Posts

Hello. Im using a code i found on this website i think, when i was searching about how to put RSS on my website, so i tested a bit. But i have  problem. When i used the code on a blank page the text got messed up. åäö and other special dident display right.

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

Solved it by removing "charset=iso-8859-1"

 

But now that i integrated it on the website i have the problem again.

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Website</title>
<meta http-equiv="content-type" content="text/html" />

<link href="../design/blend/default.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

This is the code i have ontop of all pages (since it is included on all pages)

 

Anyway, everything on the website works, exept for the rss text that is imported. So i was thinking maybe its not my code.

 

I have 4 files included.

Header, Left side, Right side and Footer.

And then the actuall page were the content is, in this case the RSS. Places in the center, between the Left and Right sides.

 

So å ä ö is working on all the included pages but not in the RSS content.

I just tested and i can even echo out å ä ö Right in the RSS content and it works.

 

Is there some way to fix this?

 

 

Here is the code.

<?php
function getRSS($rss_url) {
   echo '<h1>' . $rss_url . '</h1>';
   $content = file_get_contents(trim($rss_url));
   if ($content) {
      $xml = new SimpleXmlElement($content);
      if (count($xml->channel->item)) {
         foreach($xml->channel->item as $entry) {
            echo "<a href='$entry->link' title='$entry->title' target='_blank'>" . $entry->title . "</a><br />";
            echo "$entry->description ";
             echo '<a href="rsstest.php">Rss Test</a> Å Ä Ö  å ä ö';
         }
      } else if (count($xml->item)) {
         foreach($xml->item as $entry) {
            echo "<a href='$entry->link' title='$entry->title'>" . $entry->title . "</a><br />";
            echo "$entry->description ";
             echo '<a href="rsstest.php">Rss Test</a> Å Ä Ö  å ä ö';
         }
      }
   }
}

function createRSS($url) {
   $filename = "rss.txt";
   $fp = fopen($filename, "a+");
   
   if (!$fp) {
      echo ('File was not written');
   } else {
      fwrite ($fp, $url."\n");
      fclose ($fp);
      
      echo 'File written </br>';
   }
}

if ($_POST['action'] == 'Add URL') {
   createRSS($_POST['url']);
}

$rss_urls = file('rss.txt');
foreach ($rss_urls as $url) {
   getRSS($url);
}

?>
<form method="post" action="rsstest.php">
   <input type="text" name="url" /><br />
   <input type="submit" name="action" value="Add URL" />
</form>

Link to comment
https://forums.phpfreaks.com/topic/153574-solved-rss-having-problem-with-the-text/
Share on other sites

It's a charset issue, try this on top of your php before anything else (even space) :

 

<?php
header('Content-Type: text/html; charset=utf-8');
?>

 

In the html :

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 

 

You can also convert special characters into htmlentities like that :

<?php
$code = htmlentities($entry->title, ENT_NOQUOTES, "UTF-8");
?>

 

And better to use HTML 4.01 instead of XHTML if you serve it as text/html any way...

It's a charset issue, try this on top of your php before anything else (even space) :

 

<?php
header('Content-Type: text/html; charset=utf-8');
?>

 

In the html :

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 

 

You can also convert special characters into htmlentities like that :

<?php
$code = htmlentities($entry->title, ENT_NOQUOTES, "UTF-8");
?>

 

And better to use HTML 4.01 instead of XHTML if you serve it as text/html any way...

 

The first 2 codes dident help, instead of solving the problem it made the text problem reversed :)

RSS was working but the rest of the website got messed up. Used your last code and its now working.

 

Thank you :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.