Wordpress摘录功能,输出不良

My first question here:

I am using this code to show excerpts on my Wordpress. It allows me to show tags within the excerpt and it works OK, but the problem is when a have a word that is linked, after it I always get one space before the comma.

Example:

<a href="www.google.com">Google</a>, <a href="www.yahoo.com">Yahoo</a>

Output:

Google , Yahoo

The space after the comma is on purpose and it should be there. The one before is one too much.

Any tips on how to fix this?

Code that I use in order to define excerpt:

function new_wp_trim_excerpt($text) {
    $raw_excerpt = $text;
    if ( '' == $text ) {
        $text = get_the_content('');

        $text = strip_shortcodes( $text );

        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
        $text = strip_tags($text, '<a>');
        $excerpt_length = apply_filters('excerpt_length', 70);


        $words = preg_split('/(<a.*?a>)|
||\t|\s/', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE );
        if ( count($words) > $excerpt_length ) {
            array_pop($words);
            $text = implode(' ', $words);
            $text = $text . $excerpt_more;
        } else {
            $text = implode(' ', $words);
        }
    }
    return apply_filters('new_wp_trim_excerpt', $text, $raw_excerpt);

}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'new_wp_trim_excerpt');

It appears to be an issue with your regex, if you add a comma after the <a.*?a> does that help? Here's the regex line with the comma included:

$words = preg_split('/(<a.*?a>,)|
||\t|\s/', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE );