How to exclude smileys from image count…
-
I have found a fairly accurate word/image counter, and have made it work nice on my blog. The only thing i don’t like is that the image counter is counting the smileys as well.. They’re a part of the text, and I don’t consider the nether text nor images… So what I would like to do is to modify this script so that it gives me the image count without counting the smileys… Guess it’s supposed to be something like NOT or something in the php, but I’m totally new to that… This is the code for the plugin:
<?php
/*
Plugin Name: Word Count
Plugin URI: https://www.jonas.rabbe.com/archives/2005/05/06/word-count-plugin-for-wordpress/
Description: This plugin counts the number of words and images per post.
Version: 1.0
Author: Jonas Rabbe
Author URI: https://www.jonas.rabbe.com/
*/// This just echoes the chosen line, we'll position it later
function teb_word_count($display = true) {
global $wpdb, $id;
$post = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");$post_content = apply_filters('the_content', $post);
$words = trim(strip_tags($post_content));
if( $words == '' ) {
$wordcount = 0;
} else {
$words = explode(' ', $words);
$wordcount = count($words);
}
$ret_words = number_format($wordcount) . ' ' . ($wordcount == 1 ? 'ord' : 'ord');$imagecount = preg_match_all('/<img/', $post_content, $images);
$ret_images = number_format($imagecount) . ' ' . ($imagecount == 1 ? 'bilde' : 'bilder');$text = $ret_words . ($imagecount > 0 ? ', ' . $ret_images : '');
if( !$display ) {
return $text;
}echo $text;
}
?>All response is appreciated ??
My regards
- The topic ‘How to exclude smileys from image count…’ is closed to new replies.