2 stk May 16, 2005 04:09

Wonder if anyone can help... I have many posts that don't show the word count, just says 0. I can only assume it does the count when the post is originally created, and since I have a few years of posts from Mambo and other softwares that I have converted over... is there a way to update the word count for all posts? :-/
Savage702,
8| Odd.
I just turned it on for my site, using the above code and it seems to be functioning as expected ... posting the number of words in the "post", as reported in the evo_posts table, under the field "post_wordcount".
Keep in mind that the wordcount doesn't tally what's written in image alt tags, comments, trackbacks, etc. JUST the words contained in the "post_content" field.
Can you point a link to your site?
Have a look in the database and see if those fields are correctly populated. The word count will change each time you edit your post (unless you add as many words as you delete ;) ).
-stk :D
Well, I took a better look, and figured it out. It wasn't actually ALL of the posts prior to coming over to b2e, but most. In Mambo, and other softwares, I sometimes had to put many br tags in a post, or other such items that the html checker chokes on.
So what I've noticed is that any of my imported posts that have stuff the checker doesn't like, it won't show a word count.
Ahhh. So Mambo (and these other software packages) aren't written to XHTML standards, like b2evo?
The correct XHTML form of the old <br> tag, is <br /> (self-closing).
Glad you've gotten figured out.
-stk :D
stk wrote:
Ahhh. So Mambo (and these other software packages) aren't written to XHTML standards, like b2evo?
The correct XHTML form of the old <br> tag, is <br /> (self-closing).
Glad you've gotten figured out.
-stk :D
Sometimes I just have to give myself a good punch to the head to put things back in place. heheh ;)
Mambo let you do pretty much whatever you wanted to do, and I didn't even know the difference with the self closing tag... I just threw in br tags left and right in about a years worth of posts. I'm gonna have to go through the database and do a mass replace.
BTW, you already know my site, we traded a number of emails last week. :p
I thought it might be you, Mark, but when I took a quick peek at your site, I didn't see a word count anywhere, so I didn't want to ASSuME! ;)
-stk
stk wrote:
I thought it might be you, Mark, but when I took a quick peek at your site, I didn't see a word count anywhere, so I didn't want to ASSuME! ;)
-stk
Word count on a post by post basis, not overall total. Each post next to the category. The only reason I really looked at it was because I wanted to put an overall word count somewhere, and when I saw old posts not having on, I thought it would come out inaccurate.
In other news, my girlfriend and I looked over your site together last night... love all the stories about your little Oop! :D The videos are a riot!
I'm having trouble with this word count, it displays words containing non-7bit charachters, like the norwegian æ, ø and å's as two or more words, depending on the count of special characters.
oneword is counted as one
onæword is counted as two
oneæwoård is counted as three
...and so on. Any ideas on how to bypass this?
--
Christian
Here's what I would do ...
(1) report this as a bug and/or feature request
(2) Dive into the code to find the function that does the counting. It may be that you can hack the PHP code to allow for such characters.
(3) IF you're successful with (2), then post again to your feature request with your solution.
If I get some free time, I'll have a look at the "wordcount function" (wherever it might be) to see if I see a simple solution to your problem.
What character set are you using on your pages?
-stk
stk wrote:
Here's what I would do ...
(1) report this as a bug and/or feature request
(2) Dive into the code to find the function that does the counting. It may be that you can hack the PHP code to allow for such characters.
(3) IF you're successful with (2), then post again to your feature request with your solution.
If I get some free time, I'll have a look at the "wordcount function" (wherever it might be) to see if I see a simple solution to your problem.
What character set are you using on your pages?
-stk
Sorry, just back from vacation.
I'll try to report it as a bug/feature later on, I'm not familiar with PHP at all, so actions 2 and 3 is a bit out of my grasp.
I'm using the Norwegian (Bokmål) charachter set.
Thank you for your reply.
--
Christian Jacobsen
OKAy ...
The function that does the counting looks like THIS ... in /b2evocore/_functions_bposts.php ...
/*
* bpost_count_words(-)
*
* Returns the number of the words in a string, sans HTML
*/
function bpost_count_words($string)
{
$string = trim(strip_tags($string));
if( function_exists( 'str_word_count' ) )
{ // PHP >= 4.3
return str_word_count($string);
}
/* In case str_word_count() doesn't exist (to accomodate PHP < 4.3).
(Code adapted from post by "brettNOSPAM at olwm dot NO_SPAM dot com" at
PHP documentation page for str_word_count(). A better implementation
probably exists.)
*/
if($string == '')
{
return 0;
}
$pattern = "/[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-\-|:|\&|@)]+/";
$string = preg_replace($pattern, " ", $string);
$string = count(explode(" ", $string));
return $string;
}
First ... IF the version of PHP allows for str_word_count ... it uses that PHP function (you can learn more about that particular funciton by doign a google search ... "php doc str_word_count")
IF the version of PHP doesn't have that function ... then something else is done. IF that's what's done ... then ...
It seams to me that the $pattern variable replaces things with a SPACE. You could probably introduce another $pattern function, but replace it with a non-space .. for all your problem characters. Just a guess.
After the $string = preg_replace ... ;
Try
$pattern = "/[^(\æ|\ø|)+/";
$string = preg_replace($pattern,"",$string);
Which will JOIN any words with those characters, thus REMOVING any spaces & counting it as one word (since the count is done on "exploding" all the things BETWEEN spaces).
Make sense?
That's where I would START anyway ... I'm not 100% certain that the pattern syntax is correct, as it's untested (cause we don't use that char set).
Hope this helps! (Dive in!) ;)
-stk :D
Bill,
All you need to do is add
wherever you want the word count to show, in your _main.php.
Note that comments and ALT test in IMG tags do not count toward the total word count.
Cheer,
-stk :D
PS - The emai-blog has been updated to include blog text in the email (just thought I'd let you know ;) )