Jump to content

Problem with str_word_count()


atitthaker

Recommended Posts

I am having little problem with understanding behaviour of str_word_count().

When I am using "--" in my string in the middle of a word, it breaks word in between and does not include"--" in the counting.

Code:

//counting number of words in the string "This is sample string and th--is is another", with getting the words option...

print_r(str_word_count("This is sample string and th--is is another",1));

and the output I get is:

Array
(
    [0] => This
    [1] => is
    [2] => sample
    [3] => string
    [4] => and
    [5] => th
    [6] => is
    [7] => is
    [8] => another
)

As u can see, the word "th--is" is broken and "--" is not taken under the consideration...
I am using PHP 5.0.2.

Plz help...
Thanks
Link to comment
Share on other sites

just out of curiosity, why are you using -- in the middle of your strings?  I'm looking at your example string and it SEEMS to me that you are using -- as a seperator for multiple values, that you would maybe later on explode the string at the -- to form an array? I may be way off here, but is that what it's for?
Link to comment
Share on other sites

Thanks for the reply...
I am a new learner of PHP and I was just trying different things. It's is true that it's meaningless to put "--" in the middle of the string, but I was just trying the thing. As it works with "-" I thought it would work with "--" too. but it seems it is just for "-" only and not for "--".

Thanks once again.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.