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

    Join Date
    May 2000
    Posts
    30
    Rep Power
    14
    I am trying to parse out a string. Lets say the string is x length with spaces every so often. They spaces are random. I want to parse out every 50 characters, but if that 50th character isn't a space to lengthen what it is going to parse out until it reaches a space. After that do the loop until there is no more string left to parse.

    --Any help is greatly appreciated since I have been driving myself insane over this! THANKS!
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    7
    Rep Power
    0
    $c = 0;
    $pos = 0;
    while ( $c < strlen($text) )
    {
    $c += 50;
    for ($more = $c; $more < strlen($text) AND $text[$more] != ' '; $more++)
    echo "$more <br>n";
    $ntext[] = $more . '|' . substr($text, $pos, ($more - $pos));
    $pos = $more;
    $c = $more;
    }

    if (isset($ntext))
    for ($count = 0; $count < count($ntext); $count++)
    echo "$count $ntext[$count]<br>n";


    $text is your initial string, $ntext[] if your exploded version.

    Chris Lee
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    7
    Rep Power
    0
    oops dump the

    echo "$more<br>n";

    and replace with

    {}

    hehe, debug code.

    Chris Lee
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    30
    Rep Power
    14
    THANKS!!!! That helped emensly. I was just goofing up in a couple places but now I see what I did wrong! 1,000 thank yous!!! :-)

    -Adam Baldwin

Similar Threads

  1. array explode ( string separator, string string [, int limit])
    By beemee_freeserv in forum HTML Programming
    Replies: 4
    Last Post: February 5th, 2004, 10:56 AM
  2. SDL_ttf string parsing
    By aerea in forum C Programming
    Replies: 0
    Last Post: January 12th, 2004, 07:22 PM
  3. Parsing and formating a string through XSL
    By relativity in forum XML Programming
    Replies: 3
    Last Post: January 8th, 2004, 06:35 AM
  4. Parsing and rearranging a specific string
    By bitesize in forum PHP Development
    Replies: 2
    Last Post: October 30th, 2003, 04:53 AM
  5. Parsing a string based on one character
    By geoffgarcia in forum HTML Programming
    Replies: 3
    Last Post: October 27th, 2003, 11:32 AM

IMN logo majestic logo threadwatch logo seochat tools logo