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;
}
Labels:
PHP
0 comments:
Post a Comment