Jump to content

[SOLVED] RSS feed rendered invalid due to characters from MS Word - how to filter?


cparekh

Recommended Posts

Hi,

 

I've created a rss feed for a blog (where the blog sits behind mod_auth) so that the rss feed is available without logging in. Articles/posts are usually added directly from Word bringing with them a number of invalid characters. "Smart-Quotes" has been turned off on MS Word but some other characters still get through.

 

Posted below is the code I've used to pull the feed data directly from the db - hopefully someone can point me in the right direction to create some sort of filter so the feed is valid...

 

I've used the html_entity_decode() and strip_slashes() functions to get some control over the output but it needs more...

 


<?php header('Content-type: text/xml'); 

//db connection stuff here...

?>
<rss version="2.0">
<channel>
<title>Title of RSS Feed</title>
<description>Description of RSS Feed</description>
<link>http://www.link_to_blog</link>
<copyright>Copyright 2008.</copyright>

<?php
  
  $query = "SELECT * FROM posts WHERE post_type='post' AND post_status='publish' ORDER BY post_date_gmt DESC LIMIT 10";
  $result=mysql_query($query);
  $num=mysql_num_rows($result);
  
  function limit_text($text, $limit) {
    $text = strip_tags($text);
      $words = str_word_count($text, 2);
      $pos = array_keys($words);
      if (count($words) > $limit) {
          $text = substr($text, 0, $pos[$limit]) . ' ...';
      }
    return $text;
    }
  
  
  $i=0;
  while ($i < $num) {

    $post_id=mysql_result($result,$i,"id");
$post_title=mysql_result($result,$i,"post_title");
    $post_content=mysql_result($result,$i,"post_content");

$post_title = html_entity_decode($post_title);
$post_content= html_entity_decode($post_content);
$post_content = strip_tags($post_content);



$text = $post_content;
$limit = 50;
$description = limit_text($text, $limit);


    echo "
     <item>
     <title>$post_title</title>
     <description>$description</description>
     <link>http://www.link_to_post</link>
     <guid isPermaLink=\"true\">http://www.link_to_post</guid>
     </item>
    ";

    $i++;

  }

?>
</channel>
</rss>

 

Any help will be greatly appreciated. Thanx in advance.

 

Mik.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.