SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RSS feeds: pound signs and quotation marks

    Hi,

    When I pull news items from a RSS feed with MagpieRSS - RSS for PHP.

    It seems cannot display the pound signs and quotation marks properly, for instance, it reads,

    1. Anti-gay ?Nazi? slur causes Church of Scotland outrage

    2. �16million 'Lord of Manor' gave all money to charity - Mirror.co.uk

    Instead of,

    1. Anti-gay 'Nazi' slur causes Church of Scotland outrage

    2. £16million 'Lord of Manor' gave all money to charity

    Is there any way I can get around to it?

    Many thanks,
    Lau

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use the same character encoding as the RSS feed (or convert from the one the RSS feed uses to the one your app uses).

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by decowski View Post
    You need to use the same character encoding as the RSS feed (or convert from the one the RSS feed uses to the one your app uses).
    any possible examples or which php default functions i should look into?

    thanks,
    Lau

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am 99% sure the RSS feed uses UTF-8 and so should your app. Using anything else is asking for trouble these days.

    Character encoding is quite broad area so you will need to dig into it yourself. I'm glad to help if you come back with more specific question.

    Just read up on Unicode, UTF-8 and character encoding in RSS. Google will give you loads of material to read.

  5. #5
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by decowski View Post
    I am 99% sure the RSS feed uses UTF-8 and so should your app. Using anything else is asking for trouble these days.

    Character encoding is quite broad area so you will need to dig into it yourself. I'm glad to help if you come back with more specific question.

    Just read up on Unicode, UTF-8 and character encoding in RSS. Google will give you loads of material to read.
    thanks I will look it up. I am sure that I am using UTF-8 on my html document, below is the actual code,

    PHP Code:
    <!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=utf-8" />
    <
    title>Web Design</title>
        
    <
    style type="text/css" media="screen">
        @
    import url(css/slider.css);
    </
    style>

    <!-- 
    adding jquery -->
    <
    script type="text/javascript" src="js/jquery/jquery-1.3.2.js"></script>

    <!-- adding JDOM -->
    <script type="text/javascript" src="js/JDOM/JDOM.js"></script>

    <!-- adding slide show -->
    <script type="text/javascript" src="js/slider/addLoadEvent.js"></script>
    <script type="text/javascript" src="js/slider/moveElement.js"></script>
    <script type="text/javascript" src="js/slider/prepareSlideshow.js"></script>

    <script type="text/javascript">
    $(document).ready(function(){
        
        //$("#contents:ul:li", this).fadeIn(2000);
        $("#contents").delay(1000, function(){$("#contents").fadeIn(2000)});
                    
        // function for sliding in when hover
        $('#contents').hover(function(){
            $(".caption", this).stop().animate({top:'330px'},{queue:false,duration:160});
            $(".controller", this).fadeIn("slow");
        }, function() {
            $(".caption", this).stop().animate({top:'360px'},{queue:false,duration:160});
            $(".controller", this).fadeOut("slow");
        });
                
    });

    // function for delay 
    jQuery.fn.delay = function(time,func){
        return this.each(function(){
            setTimeout(func,time);
        });
    };

    // function for toggle on one click
    jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
    };
    </script>

    </head>
    <body>
     
    <!--slider-->  
    <div id="slider">

    <!--viewer-->  
    <div id="viewer">
          
        <!--content--> 
        <div id="contents">   
              <ul>
                  <li>
                      <h1 class="caption"><img src="img_iconies/icon_gt.png" /> Media scrum outside the golden temple in Amritsar</h1>
                      
                      <!--controller-->
                      <div class="controller">

                        <div class="controller_left">
                            <a href="#" onclick="moveContent4(); return false;">&laquo;</a>
                        </div>
                        
                        <div class="controller_right">
                            <a href="#" onclick="moveContent1(); return false;">&raquo;</a>
                        </div>
                      </div>
                      <!--controller-->
                      
                      <p><a href="http://www.globaltolerance.com/our-clients/belief/elijah-interfaith-institute-hh-dalai-lama"><img src="img_slidies/pic1.jpg" /></a></p>

                  </li>
                  
                  <li>
                      <h1 class="caption"><img src="img_iconies/icon_gt.png" /> Yunyun and Umada march on the ‘Inter-stellar’ day of tolerance for UN recognition</h1>
                      
                      <!--controller-->
                      <div class="controller">
                        <div class="controller_left">
                            <a href="#" onclick="moveContent5(); return false;">&laquo;</a>
                        </div>

                        
                        <div class="controller_right">
                            <a href="#" onclick="moveContent2(); return false;">&raquo;</a>
                        </div>
                      </div>
                      <!--controller-->
                      
                      <p><a href="http://www.globaltolerance.com/our-clients/belief/jedi-knights"><img src="img_slidies/pic2.jpg" /></a></p>
                  </li>
                  
                  <li><!--RSS-->
        <div id="rss"> 
            
            <!--head-->

            <div class="head">
                
                <!--col_left-->
                <div class="col_left">
                    <!--
                    <ul>
                        <li><a href="0" onclick="$('#viewer').fadeIn(); JDOM.ajaxGet('content_rss.php?startRow=0', 'content_rss'); return false;"><< previous</a></li>
                        <li><a href="3" onclick="$('#viewer').fadeIn(); JDOM.ajaxGet('content_rss.php?startRow=3', 'content_rss'); return false;">next >></a></li>
                    </ul>
                   -->
                </div>
                <!--col_left-->
                
                 <!--col_right-->
                <div class="col_right">
                    <a href="http://globaltolerance.com/news/"><img src="img_layouties/logo_pulse.jpg" /></a>

                </div>
                <!--col_right-->
                
            </div>
            <!--head-->
            
            <!--body-->
            <div id="content_rss" class="body">

                        
                            
                <!--item-->
                <div class="item item_toppest">

                    
                    <!--item_left-->
                    <div class="item_left">
                                       
                    </div>
                    <!--item_left-->
                    
                    <!--item_right-->
                    <div class="item_right">
                        <div class="title"><a href="http://globaltolerance.com/pulse/">Scared Somalis running out of food as battles rag...</a></div>
                        <div class="desicription"></div>

                        <div class="date">Friday, May 15th, 2009</div>
                    </div>
                    <!--item_right-->
                </div>
                <!--item-->
                
             
                
             
                <!--item-->
                <div class="item">
                    
                    <!--item_left-->

                    <div class="item_left">
                                       
                    </div>
                    <!--item_left-->
                    
                    <!--item_right-->
                    <div class="item_right">
                        <div class="title"><a href="http://globaltolerance.com/pulse/">Anti-gay ?Nazi? slur causes Church of Scotland ou...</a></div>
                        <div class="desicription"></div>
                        <div class="date">Friday, May 15th, 2009</div>

                    </div>
                    <!--item_right-->
                </div>
                <!--item-->
                
                 
                <!--item-->
                <div class="item">
                    
                    <!--item_left-->
                    <div class="item_left">
                                       
                    </div>

                    <!--item_left-->
                    
                    <!--item_right-->
                    <div class="item_right">
                        <div class="title"><a href="http://globaltolerance.com/pulse/">Election 2009: Numbers game sans big issues (Calc...</a></div>
                        <div class="desicription"></div>
                        <div class="date">Friday, May 15th, 2009</div>
                    </div>
                    <!--item_right-->

                </div>
                <!--item-->
                
                 
                <!--item-->
                <div class="item">
                    
                    <!--item_left-->
                    <div class="item_left">
                                       
                    </div>
                    <!--item_left-->
                    
                    <!--item_right-->

                    <div class="item_right">
                        <div class="title"><a href="http://globaltolerance.com/pulse/">US churches seek action from Obama on immigration...</a></div>
                        <div class="desicription"></div>
                        <div class="date">Friday, May 15th, 2009</div>
                    </div>
                    <!--item_right-->
                </div>
                <!--item-->

                
                         
         
            </div>
            <!--body-->
            
            <!--foot-->
            <div class="foot">
                <img src="img_iconies/icon_gt.png" /> click on the news item for more on this and other pulse stories!
            </div>
            <!--foot-->
        
        </div> 
        <!--RSS--></li>

                  
                  <li>
                      <h1 class="caption"><img src="img_iconies/icon_gt.png" /> Blair faith envoy hosts combat-scarred Christian and Muslim heads</h1>
                      
                      <!--controller-->
                      <div class="controller">
                        <div class="controller_left">
                            <a href="#" onclick="moveContent2(); return false;">&laquo;</a>
                        </div>
                        
                        <div class="controller_right">

                            <a href="#" onclick="moveContent4(); return false;">&raquo;</a>
                        </div>
                      </div>
                      <!--controller-->
                      
                      <p><a href="http://www.globaltolerance.com/our-clients/belief/imam-and-pastor"><img src="img_slidies/pic4.jpg" /></a></p>
                  </li>
                  
                  <li>
                      <h1 class="caption"><img src="img_iconies/icon_gt.png" /> Wallace & Gromit drive for a million wrong trousers</h1>

                      
                      <!--controller-->
                      <div class="controller">
                        <div class="controller_left">
                            <a href="#" onclick="moveContent3(); return false;">&laquo;</a>
                        </div>
                        
                        <div class="controller_right">
                            <a href="#" onclick="moveContent5(); return false;">&raquo;</a>
                        </div>
                      </div>

                      <!--controller-->
                      
                      <p><a href="http://www.globaltolerance.com/our-clients/young-people/wallace-gromit"><img src="img_slidies/pic5.jpg" /></a></p>
                  </li>
              </ul>
        </div>
        <!--content-->
        
        <!--mask-->
        <div class="mask_right">
        </div>

        
        <div class="mask_left">
        </div>
        <!--mask-->
        
    </div>
    <!--viewer--> 

    <!--navigator-->
    <div id="navigator">
        
        <ul id="linklist">
            <li><a href="#"><img src="img_layouties/tab_sincerity.png" /></a></li>
            <li><a href="#"><img src="img_layouties/tab_inspiration.png" /></a></li>

            <li><a href="#"><img src="img_layouties/tab_understanding.png" /></a></li>
            <li><a href="#"><img src="img_layouties/tab_humility.png" /></a></li>
            <li><a href="#"><img src="img_layouties/tab_beneficence.png" /></a></li>
        </ul>
        
    </div>
    <!--navigator--> 

    </div>
    <!--slider--> 
     
    </body>
    </html> 

  6. #6
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It certainly looks like you are. Post the code that generates this page.

  7. #7
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by decowski View Post
    It certainly looks like you are. Post the code that generates this page.
    this is the script that I use,

    Code:
    <?php
            require_once 'magpierss/rss_fetch.inc';
            
            $url = 'http://pipes.yahoo.com/pipes/pipe.run?_id=a39fa4f77e90609914ad4a1be7b07a9e&_render=rss';
            $rss = fetch_rss($url);
            $items = array_slice($rss->items, 0, 8);
     
            foreach ($items as $item) {
                $title = $item['title'];
                $link   = $item['link'];
                $imageURL   = $rss->image['url'];
                $date = $item['date_timestamp'];
                $desc = $item['description'];
                $source = trim ($link, "http://");
                $source = explode("/", $source);
                $source = $source[0];
                
                /*if (strlen($title) >= 50)
                    {
                    $title = substr($title,0,49)."...";
                    }
                */
                $desc = eregi_replace('<br>',' ', $desc); 
                $desc = strip_tags($desc);
                
                if (strlen($desc) >= 100)
                    {
                    $desc = substr($desc,0,99)."...";
                    }
    ?>
          <!--item-->
                <div class="item">
                    
                    <!--item_left-->
                    <div class="item_left">
                        <?php if(!empty($imageURL))
                        {
                        ?>
                        <div class="left_img"><img src="<?php echo $imageURL;?>"/></div>
                        <?php
                        }
                        ?>               
                    </div>
                    <!--item_left-->
                    
                    <!--item_right-->
                    <div class="item_right">
                        <div class="title"><a href="<?php echo $link;?>" target="_blank"><?php echo $title;?></a></div>
                        <div class="desicription"><?php echo $desc;?></div>
                        <div class="date"><strong><?php echo date("j F", $date);?></strong>, <?php echo date("H:i", $date);?></div>
                        <div class="date">source: <a href="http://<?php echo $source;?>"><?php echo $source;?></a></div>
                    </div>
                    <!--item_right-->
            </div>
        <!--item-->
     
     <?php
                }
                ?>

  8. #8
    SitePoint Evangelist
    Join Date
    Dec 2008
    Location
    Plymouth, United Kingdon
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have managed to fix the bug. Magpie RSS uses ISO-8859-1 as the default output encoding because this is PHP's default. To force UTF-8 encoding, add this to your page's PHP, before you load Magpie RSS:

    PHP Code:
    define('MAGPIE_OUTPUT_ENCODING''UTF-8'); 
    for instance,

    PHP Code:
    define('MAGPIE_OUTPUT_ENCODING''UTF-8');
    require_once 
    'magpierss/rss_fetch.inc'
    thanks,
    Lau


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •