Custom Excerpt in PHP

Published by: 9

php

Custom excerpt function makes easy to make a simple excerpt text. Using reg-exp , we can easily create the small text. In my function , There are two parameters, First one is text content and another one is length of the string .
You can use this custom excerpt into your own project.

 Function Code is given below:

function custom_excerpt($text,$numb) {
$text=strip_tags($text);
$text=str_replace("\n","",$text);
$text=preg_replace("/\s\s+/"," ",$text);
$text = preg_replace('@<script[^>]*?>.*?@si', '', $text);
$text = str_replace(']]>', ']]>', $text);
$text = preg_replace('`\[[^\]]*\]`','', $text);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text," "));
$etc = " ...";
$text = $text.$etc;
}
return $text;
}

Share this:

The following two tabs change content below.

Bivash Kanti Pal

Hi guys, This is the place where developers are sharing there thoughts....

Latest posts by Bivash Kanti Pal (see all)

9 comments

  1. Pingback: Your AdSense Income Calculator

  2. Mitch

    Howdy! I know this is somewhat off-topic but I had to ask.
    Does operating a well-established blog like yours take a large amount of work?
    I am brand new to running a blog but I do write in my journal everyday.
    I’d like to start a blog so I can easily share my experience and views online.
    Please let me know if you have any kind of ideas or tips for new aspiring bloggers.

    Thankyou!
    Mitch recently posted…MitchMy Profile

    1. Bivash Kanti Pal Post author

      No no , it will not take a large amount of work, just book a domain & hosting or even you can start with Google Blogspot or WordPress free blog hosting .

  3. agence girafe

    Great article! This is the type of info that should be shared across the
    net. Disgrace on Google for not positioning this post upper!
    Come on over and consult with my site . Thank you =)
    agence girafe recently posted…agence girafeMy Profile

  4. Thelma

    Hmm is anyone ellse experiencing problems with the picturtes on this blog loading?
    I’m trying to find out if its a problem on my end or if
    it’s the blog. Any responses would be grwatly appreciated.
    Thelma recently posted…ThelmaMy Profile

Leave a Reply

Your email address will not be published. Required fields are marked *

Result of *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge