I am presently utilizing a custom function to alter the size of my wordpress excerpt as well as preserve formatting.

Things I want would be to have the ability to set the variable $excerpt_length to ensure that for that first publish during my loop, the excerpt is 125 words lengthy and after that it's 55 words.

I am a new comer to php so would appreciate any tips on how to personalize the next function to ensure that I'm able to set the space?

Thanks! :)

    function improved_trim_excerpt($text) {
        global $post;
        if ( '' == $text ) {
                $text = get_the_content('');
                $text = apply_filters('the_content', $text);
                $text = str_replace('\]\]\>', ']]>', $text);
                $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
                $text = strip_tags($text, '<p>');
                $excerpt_length = 125;
                $words = explode(' ', $text, $excerpt_length + 1);
                if (count($words)> $excerpt_length) {
                        array_pop($words);
                        array_push($words, '<small>...</small> </p>');
                        $text = implode(' ', $words);
                }
        }
        return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');