web analytics

Custom Excerpt in 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=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;

Bivash Kanti Pal

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

9 thoughts on “Custom Excerpt in PHP

    • October 15, 2013 at 10:35 pm

      Thanks Subhasish , for your interest to our blog.

  • May 14, 2014 at 11:17 am

    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.


    • May 15, 2014 at 12:55 pm

      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 .

  • May 18, 2014 at 5:42 am

    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 =)

  • August 30, 2014 at 12:09 pm

    Fine way of describing, and pleasant paragraph
    to get facts regarding my presentation topic, which i am going to convey in college.

  • October 1, 2014 at 6:44 am

    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.

    • October 3, 2014 at 7:12 am

      Yes, there was a Server issue. Now its solved.


Leave a Reply

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

Result of *Captcha loading...

Do NOT follow this link or you will be banned from the site!