Welcome Guest, Not a member yet? Register   Sign In
Parsing Blog Posts for first <p> and <img> elements
#4

[eluser]waynhall[/eluser]
Actually, I'll just keep them in the view, since I'd have to loop through all of them in the controller.

I improved the get_excerpt function to fall back on CI's word_limiter (text helper)
Code:
function get_excerpt($content) {        // Returns contents of the first <p> tag
        
        $start = stripos($content, '<p');
        
        if( ($start !== FALSE) && ($start < 200) ) {   // if reasonably close to top
            
            $p_open = strpos($content, '>', $start) + 1;
            $p_close = strpos($content, '</p>', $p_open);
            $length = $p_close - $p_open;
            
            if($length > 200) {    // if a reasonable size paragraph
                $p_contents = substr($content, $p_open, $length);
            } else {
                $p_contents = word_limiter(strip_tags($content));
            }
            
            return $p_contents;
        } else {
            
            $first_bit = word_limiter(strip_tags($content));
            return $first_bit;
        }
    }


Messages In This Thread
Parsing Blog Posts for first <p> and <img> elements - by El Forum - 07-29-2011, 10:40 PM
Parsing Blog Posts for first <p> and <img> elements - by El Forum - 07-30-2011, 04:53 AM
Parsing Blog Posts for first <p> and <img> elements - by El Forum - 07-30-2011, 08:56 AM
Parsing Blog Posts for first <p> and <img> elements - by El Forum - 07-30-2011, 09:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB