How to clean RSS <description> HTML Code?

Discussion in 'PHP' started by kuser, Apr 6, 2013.

  1. #1
    When I get the RSS code via an API (they post to m server) i do something like this:



    $this_news=htmlentities($this_news);

    $this_news=mysql_real_escape_string($this_news); echo "X2:".strlen($this_news);
    $this_title=mysql_real_escape_string($this_title);



    however the news are looking like:

    http://latinotimes.com/softgroups/53331-international-youth-soccer-s-dallas-cup-set-to-start-in-new-cotton-bowl-home.html

    they do not convert that shi... RSS HTML code to real html code
     
    kuser, Apr 6, 2013 IP
  2. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #2
    RSS HTML is not HTML, I bet you have something like this:
    <item>
    <title>Google SEO Speed And Penalizing Factors</title>
    <description>Blah</description>
    <link>
    http://chkme.com/read-google-seo-speed-and-penalizing-factors
    </link>
    <guid isPermaLink="true">
    http://chkme.com/read-google-seo-speed-and-penalizing-factors
    </guid>
    <pubDate>Sun, 17 Mar 13 22:05:14 -0600</pubDate>
    </item>
    HTML:
    So assuming that:
    $f = file_get_contents("website.tld/rss.xml");

    You can try:
    $array = json_decode(json_encode((array) simplexml_load_string($f)),1);

    So then your $array at a certain point will be like this:
    ['title'] = "Your Title";
    ['description'] = "Body text here";
    ['link'] = "yourlink.html";
    etc...


    So basic PHP and HTML here, ie:
    <h3><?php echo $array['title];?></h3>
    <p><?php echo $array['description'];?></p>
    <hr><p align="right"><small><a href="<?php echo $array['link'];?>">Read More</a></small></p>
    
    PHP:
    Basically and in few words, RSS is not HTML formatted. If the API you are calling are returning HTML Code but encoded, well you will have to use html_entity_decode and not htmlentities.

    But once again, mine are just examples and without an idea of how the API return you data I cannot exactly give you a right answer/solution.
     
    YoGem, Apr 6, 2013 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    to remove the html from the description we have the php.net/strip_tags function! :)
     
    EricBruggema, Apr 6, 2013 IP
  4. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #4

    Eric, do you think he want to transform HTML in RSS or HTML in RSS? I am lost!
     
    YoGem, Apr 7, 2013 IP
  5. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #5
    Im lost to, just due the fact he doesn't respond quick to given answers :p so i have no idea....
     
    EricBruggema, Apr 7, 2013 IP