June 22nd, 2000, 08:21 PM
-
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!
June 22nd, 2000, 09:25 PM
-
$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
June 22nd, 2000, 09:28 PM
-
oops dump the
echo "$more<br>n";
and replace with
{}
hehe, debug code.
Chris Lee
June 22nd, 2000, 09:43 PM
-
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