#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    44
    Rep Power
    15
    Hi, i am accepting a string input from a textarea. My problem is that if a user sticks in a long unbroken string such as "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" my entire page will try to fit it. I need to be able to check within a string to see if any of the words within it are larger than a certain number of chars, and if it is break it at the max point.

    Hence if someone enters: "I like to addlotsofcharacterstogethertobeaproblematicchild but I am still friendly" the large word would be broken, and a " " would be added.

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    32
    Rep Power
    15
    You can get the length of a string by doing a sizeof. Example:

    $string = "blahblahblahblahblahblah";
    $length = sizeof($string);

    Hope that helps =)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    15
    If you want to analyze each word within a string then you will probably want to explode the string and loop through it or better yet, use a regexp with eregi_replace(). I've illustrated the former for you below:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $maxcharacters = 15; // change to maximum number of characters to accept
    $string = explode(" ", $full_string);
    $sizeof_string = count($string);
    for($i=0; $i < $sizeof_string; $i++) {
    if(strlen($string[$i]) > $maxcharacters) {
    $string[$i] = " ";
    }
    }
    [/code]


    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>

    [This message has been edited by TDavid (edited September 02, 2000).]

Similar Threads

  1. form validation!!!
    By boskyvora in forum HTML Programming
    Replies: 5
    Last Post: February 6th, 2004, 07:45 AM
  2. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:40 PM
  3. dynamic JS form validation
    By rgoel in forum HTML Programming
    Replies: 2
    Last Post: January 8th, 2004, 01:44 AM
  4. Replies: 2
    Last Post: December 23rd, 2003, 04:23 AM
  5. Replies: 0
    Last Post: December 22nd, 2003, 08:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo