Oct 6, 2013
0 0

Custom Excerpt in PHP

Written by

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;

Share this:
Article Categories:

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

Comments to Custom Excerpt in PHP

  • very help full post…

    subhasish ghosh October 15, 2013 2:26 pm Reply
    • Thanks Subhasish , for your interest to our blog.

      Ramen Dey October 15, 2013 10:35 pm Reply
  • 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.


    Mitch May 14, 2014 11:17 am Reply
    • 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 .

      Bivash Kanti Pal May 15, 2014 12:55 pm Reply
  • 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 May 18, 2014 5:42 am Reply
  • Fine way of describing, and pleasant paragraph
    to get facts regarding my presentation topic, which i am going to convey in college.

    Irritable Bowel Syndrome Diet August 30, 2014 12:09 pm Reply
  • 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 October 1, 2014 6:44 am Reply
    • Hi,
      Yes, there was a Server issue. Now its solved.

      Bivash Kanti Pal October 3, 2014 7:12 am Reply

Leave a Comment

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

Result of *

Social Widgets powered by