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[^>]*?>.*[email protected]', '', $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;

9 thoughts on “Custom Excerpt in PHP”

  1. 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.


    1. 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 .

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

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

  4. 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.

Leave a Reply

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

Result of *Captcha loading...