SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: split long word

  1. #1
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    split long word

    thread begun in http://www.sitepointforums.com/showt...200#post192200

    as explained in the previous thread, i would like to split a word that somebody has entered in a textfield if it's longer than ,say, 40 characters, so that it wont mess upp any table layout i have when i pull it from the database... does anybody know how this would be done with php?

    /Måns

  2. #2
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a couple functions that would be useful to you, but how do you plan on storing the data from the form in the db? The string functions I'm familiar with in PHP that do this kind of thing are split() and explode() - both of which return arrays of values. It would be very easy to then cycle through that array and first insert then append the data to the field, which wouldn't affect your output at all because the data would have been combined again in the db. However, neither of these functions accept length arguments - they both look for characters.

    I've got most parts of this figured out (although I'm sure someone else has a much easier way), but there's one step missing that you/me'll still need help with:

    $mystring = "yourformsubmission";
    $string_length = strlen($mystring); //find length to be sure greater than 40 or whatever
    $last_substring = ???; //how to find a substring comprised of the last 3 characters occupying positions 38,39,40???
    $mystring_array = explode($last_substring,$mystring);

    More help, please?

    Mandi
    Love ya - mean it!

  3. #3
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops - forgot to continue the discussion about how to then translate that into your table layout dilemma...

    Before appending each new piece of the array, you could insert an HTML tag such as the <br> or a special character like a newline or carriage return (which would be caught with the <pre> tags) to break up the word on display.

    Mandi
    Love ya - mean it!

  4. #4
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, im gonna look into that...

    /Måns

  5. #5
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's also wordwrap...
    Kevin

  6. #6
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoo-hoo - that function does exactly the right thing!

    Forget me and my fancy strlen(charat(mystring))) nonsense!!!!!! Wordwrap rocks!

    Mandi
    Love ya - mean it!


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
  •