SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot DBallerz01's Avatar
    Join Date
    Jan 2004
    Location
    CT
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to search # of words in a string?

    For example:

    $string = "blah blah a blah 4asdasd blah";
    $numwords = "4";

    How can I get this result?
    http://websbests.com-Top Rated Sites Of The Web Brought By YOU!
    (submit your site guys)

    http://howology.com-Explaining How To Do Stuff ...One Step A Time

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by DBallerz01 View Post
    For example:

    $string = "blah blah a blah 4asdasd blah";
    $numwords = "4";

    How can I get this result?
    What result? The number of words in that string isn't 4?

  3. #3
    SitePoint Zealot DBallerz01's Avatar
    Join Date
    Jan 2004
    Location
    CT
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    What result? The number of words in that string isn't 4?
    ooops the number of time 'blah' occurs
    http://websbests.com-Top Rated Sites Of The Web Brought By YOU!
    (submit your site guys)

    http://howology.com-Explaining How To Do Stuff ...One Step A Time

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    substr_count() (beware of "blahblahblah" == 3)
    str_word_count()

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DBallerz01 View Post
    ooops the number of time 'blah' occurs
    substr_count() or array_unique(str_word_count($sentence,2))
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •