#1
  1. Drifting Vagabond
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    ..middle of nowhere..
    Posts
    213
    Rep Power
    16

    how to cut text and display it plus the remaining texts


    hi there!

    just wanna ask if there's a way I can limit the text length i wanna display and display the remaining text below...??

    let's say here's my string:


    $CallNum = $rows['CallNum'];

    this contains : Q179:1546:554-abc

    now i want to display this text like this:

    Q179:
    1546:
    554-
    abc

    is there a solution for that???? thanks!
    code reuse...
  2. #2
  3. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    51
    substr() and a for loop will get you where you need to be.
  4. #3
  5. Drifting Vagabond
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    ..middle of nowhere..
    Posts
    213
    Rep Power
    16
    ey sam, i bumped to some php functions where i can use it...it is WORDWRAP() ...hmmm..substr???...as i understood it, correct me if im wrong, the substr only gets the value that you selected not the other remaining texts...
    code reuse...
  6. #4
  7. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,196
    Rep Power
    2269
    Originally posted by robee
    ey sam, i bumped to some php functions where i can use it...it is WORDWRAP() ...hmmm..substr???...as i understood it, correct me if im wrong, the substr only gets the value that you selected not the other remaining texts...
    Try using explode() to break the string by either : or - ... of course, explode() removes the delimiter from the string in the process, so you'll have to code around that.
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
    The Most Important Article You Can Read as a Developer
  8. #5
  9. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,196
    Rep Power
    2269
    Actually - use str_replace() instead... as long as all of the strings are in this format, it should work...
    PHP Code:
    $string "Q179:1546:554-abc";
    $new_string str_replace(":"":<br>"$string);
    $new_string str_replace("-""-<br>"$new_string);
    echo 
    $new_string
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
    The Most Important Article You Can Read as a Developer
  10. #6
  11. Drifting Vagabond
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    ..middle of nowhere..
    Posts
    213
    Rep Power
    16
    but what if my text is like this : Q124:65748383838 ...and i want to break it into 4 to 5 letters and display it like this :

    Q124:
    65748
    38383
    3 and etc..
    code reuse...
  12. #7
  13. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    51
    Yeah, wordwrap() is much faster.

    wordwrap($string, 5);
  14. #8
  15. Drifting Vagabond
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    ..middle of nowhere..
    Posts
    213
    Rep Power
    16
    just what I thought..but drgroove just gave a gud code...ill use it in some of my apps..thanks dudes
    code reuse...
  16. #9
  17. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,196
    Rep Power
    2269
    Originally posted by robee
    just what I thought..but drgroove just gave a gud code...ill use it in some of my apps..thanks dudes
    No prob...

    You can also use arrays as the args in str_replace()...
    PHP Code:
    $find(":""-");
    $rep(":<br>""-<br>");
    $string Q179:1546:554-abc;
    $string str_replace($find$rep$string);
    echo 
    $string
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
    The Most Important Article You Can Read as a Developer
  18. #10
  19. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    51
    Where would we be without str_replace??
    PHP Code:
    $string "drgroove";
    $new_string str_replace("dr""DJ"$string);
    echo 
    $new_string
    HAHA! J/K
  20. #11
  21. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,196
    Rep Power
    2269
    Originally posted by SammyK
    Where would we be without str_replace??
    PHP Code:
    $string "drgroove";
    $new_string str_replace("dr""DJ"$string);
    echo 
    $new_string
    HAHA! J/K
    NO!!!!!
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
    The Most Important Article You Can Read as a Developer
  22. #12
  23. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    51
    HAHA! We'll never get you to conform.
  24. #13
  25. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,196
    Rep Power
    2269
    Originally posted by SammyK
    HAHA! We'll never get you to conform.
    Nope.
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
    The Most Important Article You Can Read as a Developer

IMN logo majestic logo threadwatch logo seochat tools logo