Im experiencing problems with manipulating strings. Im trying to format the input from a textarea into two strings, but don't want to just cut them in half incase it's in the middle of a word....
So im using substr() to do this with a loop....Here is my code,
<?
if (strlen($details) > 40)
{
for ($i=-1; $i >= -20; $i--)
{
if ($i == -1)
{
$temp = substr($details, 0, 40);
$temp2 = substr($temp, 40+$i);
if ($temp2 == "")
{
$end = 1;
}
}
if ($i != -1)
{
$temp = substr($details, 0, 40);
$temp2 = "substr($temp, 40+$i, $i+1)";
if ($temp2 == "")
{
$end = 1;
}
}
if (isset($end))
break;
}
}
$first = substr($details, 0, (40 + $i));
$second = substr($details, (40 + $i));
echo "$first<br>
$second";
?>
But this script cuts the strings in the wrong place, I know it's to do with the IF loops comparing each charecter in turn to " ".....But it doesn't do the compare correctly.....This should be a simple problem, but im not seeing it...!!!
Thanks,
Ian