Artem Russakovskii
Artem Russakovskii

Reputation: 22023

Is it possible to calculate the word count in a MySQL query, excluding HTML?

I'm trying to figure out if it's possible to get a loose word count in a MySQL field, ignoring HTML tags. Does anyone have a handy snippet how to do this? Alternatively, a Wordpress plugin could help.

Upvotes: 0

Views: 640

Answers (1)

superUntitled
superUntitled

Reputation: 22547

http://wordpress.org/extend/plugins/td-word-count/

The second google entry for: wordpress word count. It is an old plugin, but should still work.

The important part of the plugin is this:

foreach ($words as $word) {
    $post = strip_tags($word->post_content);
    $post = explode(' ', $post);
    $count = count($post);
    $totalcount = $count + $oldcount;
    $oldcount = $totalcount;
}

The second line invokes the strip_tags function that removes html tags.

Upvotes: 1

Related Questions