/    Sign up×
Community /Pin to ProfileBookmark

str_word_count

Hi quick question on str_word_count:

I need to work out the amount of words in a string but can’t seem to work it out. I’m using $var = str_word_count($string, 0); which should give an output like:

[0] => The
[1] => Cat
[2] => Sat
[3] => On
[4] => The
[5] => Mat

but how can i get it to return the number 5? I’m guessing the answer lies in key() and end()….

i’m sure this is really simple but i can’t quite work it out.

cheers,
Durbs

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@DurbsauthorJul 31.2005 — No worries, sorted it. I knew it would be simple in the end...
×

Success!

Help @Durbs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...