Jump to content

richardjh

Members
  • Posts

    74
  • Joined

  • Last visited

    Never

Everything posted by richardjh

  1. Thank you for the quick replies and help. I found that these three lines seem to be doing what I want: $word1 = preg_replace('/\s+/', ' ', $text); $word = explode(' ', $word1); $words = count($word); Using this I can put any amount of white space between words and the count remains the same (which I want). I will test it a bit more though before getting my hopes up.
  2. Yeah, I've used that as well and combinations of all those functions but so far I've not clinched it.
  3. I've been trying to come up with a way to accurately count a word string which includes punctuation marks. I've got close but the white-space is causing a problem. I have used a couple of functions such as str_replace and explode and I can now get an accurate count for texts with most punctuation and 'normal' white space. BUT.. If I put in three extra spaces between words the count adds 1 to the total. $words2 = str_replace("-", "", $string); // strips a hypen $words3 = str_replace(' ', ' ', $words2); // strips double spaces $words = explode(' ', $words3); This is obviously NOT a script - rather a string of text being passed through three functions to cleanse it. But as you can see it will strip two white spaces when they occur but no more. So three, four, five etc. will be counted as extra words. What else could I try to give me an accurate count? I am very raw at php. :'( thanks Richard
×
×
  • 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.