SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    Does anybody know how to count the words in a <Textarea> posted to a php script?

    basically each word is separated by a space " " so i think using the explode() function to get an array of the words, but i'm not sure how to approach this. Can somebody help?

    Thanks
    Sang N.

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should do the job for you.

    <?php

    $a = explode( ' ', $textArea );
    $numWords = count( $a );

    ?>

    or to put it all on one line:

    <?php

    $numWords = count( explode( ' ', $textArea ) );

    ?>

    Edit:

    Obviously the textarea has name="textArea" and $numWords stores the number of words.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks
    Sang N.
    -------------------------------
    Send an E-card today!
    http://ecard.vinasite.com


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
  •