1
Stewdio
News 1.2 convert Byte count to Word count
  • 2004/8/25 16:34

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


Greets,

It's not often I'm on this end of the question, but I have been making some minor modifications to News 1.2 and I was wondering what code I would use to change a display element of the news.

We're all familiar with the "xxx Bytes more" being displayed. What I would like to do is change the code so that it does a word count and thus display either "Total Words" or "xxx Words more" (I prefer total words, but either will suffice for my needs)

I suspect this is in /news/class/class.newsstory.php around line 277:

line 277: $morelink .= sprintf(_NW_BYTESMORE,$totalcount);

There also seems to be some related functions that start at around line 269:

line 269: $introcount = strlen($story['text']);
line 270: $fullcount = strlen($this->bodytext());
line 271: $totalcount = $introcount + $fullcount;

So far I have only commented out line 277 and edited a different "$morelink .=" element that was being rendered on the page, effectively eliminating the Byte's more from being displayed.

It's not important that I have a word count, but it would be a more elegant option to have instead of Bytes. I don't think anyone cares how many bytes are used for something they are reading; words at least is a bit more interesting to look at and people can relate to that a bit more imho.

Mith, or anyone else care to shed some light on this small hack?

Stew



2
Stewdio
Re: News 1.2 convert Byte count to Word count
  • 2004/8/26 14:33

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


*Punt!*

3
Dave_L
Re: News 1.2 convert Byte count to Word count
  • 2004/8/26 17:43

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Does the quantity of additional text really affect whether you're going to click the link? I think it would be less "geeky" to simply say "More ...", and don't provide either a byte-count or a word-count.

If you do want to count words, you could use str_word_count(), available in PHP 4.3.0, or preg_match_all().

4
Stewdio
Re: News 1.2 convert Byte count to Word count
  • 2004/8/27 4:25

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


Yes, in fact it does on a small level. Considering my site is now a blog, word count will tell people at a glance if it's a long or short story and they can determine whether or not they feel or have the time to read something that long (or short).

I'm not trying to be a geek and I already had what you suggested in place, but thanks for the opinion, I think.

As for using str_word_count() or preg_match_all(), would I just replace strlen() with either of your suggestions?

Amuse me, I'm the reason they write "... for Idiots" Books

5
Stewdio
Re: News 1.2 convert Byte count to Word count
  • 2004/8/28 16:43

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


*Boing!*

6
Dave_L
Re: News 1.2 convert Byte count to Word count
  • 2004/8/28 18:13

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Quote:
As for using str_word_count() or preg_match_all(), would I just replace strlen() with either of your suggestions?


str_word_count() would replace strlen().

For preg_match_all(), you'd need to use a regex pattern that matches "words".

7
Stewdio
Re: News 1.2 convert Byte count to Word count
  • 2004/8/29 7:51

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


Erm, yeah. I'll use the first one!

When I figure out what regex is, I might look into the other option

Thanks Dave, for your incredible wisdom; now where did I put that donut...

8
Mithrandir
Re: News 1.2 convert Byte count to Word count

If you have a PHP version below 4.3.0 you could also perhaps use explode():
$word_array explode(" "$text);
$num_words count($word_array);


edit: Regex may be a little more accurate as I don't know how many "false positives" will be found by the above method - but at least it is easier than regex

9
Stewdio
Re: News 1.2 convert Byte count to Word count
  • 2004/8/29 14:24

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


Well, I gave str_word_count() a shot. It's a bit innacurate, but good enough. I implemented it on a site other then my own for test purposes. That group uses word count in their own coded news, so I thought it would be alright for them.

Thanks for the info though, it gives me something to play around with when I'm bored, or just eating donuts.

Mmmm, donuts...

10
Stewdio
Re: News 1.2 convert Byte count to Word count
  • 2004/8/29 14:55

  • Stewdio

  • Community Support Member

  • Posts: 1560

  • Since: 2003/5/7 1


I figured why my count was off. I edited the $totalcount to not include the title. Good enough for me!

Login

Who's Online

276 user(s) are online (58 user(s) are browsing Support Forums)


Members: 0


Guests: 276


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits