Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ascetix

    (@ascetix)

    Hi,

    I don’t know why, but for me strip_htmltags for “img” doesn’t work properly- I see many <img> tags with some images in parsed feeds. To work it out I’ve added another preg_replace line.

    I always added “iframe” to strip_htmltags. So, now, after some additional cleanings/customisations I use:

    $feed->strip_htmltags(array('p', 'a', 'b', 'strong', 'i', 'em', 'u', 'div', 'table', 'iframe', 'td', 'tr', 'img', 'span', 'h1', 'h2', 'h3', 'h4', 'ul', 'ol', 'li' ..... /* and other tags */ ));
    $feed->strip_comments(true);
    
    [...]
    
    if ($rss_items[$i]->get_description() != '') $z = $rss_items[$i]->get_description();
        $z = str_ireplace  ('&oacute;', 'ó', $z);
        $z = str_ireplace  ('&middot;', '-', $z);
        $z = preg_replace  ('/<br\s+\/>/i', ' ', $z);
        $z = preg_replace  ('/<br\/>/i', ' ', $z);
        $z = preg_replace  ('/<br>/i', ' ', $z);
        $z = preg_replace  ('/[ \t\f]+/i', ' ', $z);
        $z = preg_replace  ('/https?[^\s]+/i', '[url]', $z);
        $z = preg_replace  ('/<img[^>]*>/i', '[img]', $z);
        $z = preg_replace  ('/[\r\n]/i', '?', $z);
    
    if ($rssdescriptionlength != 'all') {
    if(strlen($z) > $rssdescriptionlength)
     { $z = mb_substr($z, 0, $rssdescriptionlength,  'UTF-8').'... '; }
    }
        $z = str_ireplace  ('[url]', '<i>[url]</i> ', $z);
        $z = str_ireplace  ('[img]', '<i>[img]</i> ', $z);
        $z = preg_replace  ('/?[ ?]*/i', '&diams;', $z);

    It results in importing more interesting texts from rss feed. It’s also safer.

    Thread Starter ascetix

    (@ascetix)

    as an example of page with mentioned changes:
    https://blog.koszykzdomenami.pl/domenowe-wiadomosci/

Viewing 2 replies - 1 through 2 (of 2 total)