Home» »PHP - How to create an Excerpt of an article

PHP - How to create an Excerpt of an article



Here is php code to get an excerpt from a descriptions or a long text called article. Just put this code to your php file and then call this function like this get_excerpt($content, '30'). Thats all, just click like or plus one if this code works.

function get_excerpt($content, $length) {
//Break the text into an array of $length +1 number of elements
$content = explode(' ', trim($content), $length+1);

//Pop of the last element containing the remaining text (thus the +1 above)
array_pop($content);

//Put it all back together into a string
$content = implode(' ', $content);

//Add our ellipsis
$content = $content . '...';

return $content;
}

About Author:

Rahman Kurnia is a blogger, SEO fighter, who loves PHP, CSS, HTML and interested in js, ajax, c++ and much more. He love writing something informatif to help others, and to keep his knowledge on the internet.

Follow him @ Twitter | Facebook | Google +

0 comments:

Post a Comment

Like us on Facebook
Follow us on Twitter
Recommend us on Google Plus
Blog Widget by LinkWithin