I'm looping through an array of strings in PHP. Specifically, I'm looking for double dots in each array row (..). If no dots are found, the entire row is appended to a second array row. If it is found, then I split the row, put the left half in the current (second) array row, and the right half in the next row.
This is what I have so far:
$fudgedindex = 0;
$parsedrows = array('');
foreach($refinedlist as $rowtoparse)
{
$pos2 = strpos($rowtoparse, "..");
//echo $refinedlist[$index] . "<br>";
if ($pos2 === false)
{
$parsedrows[$fudgedindex] = $parsedrows[$fudgedindex] . $rowtoparse;
}
else
{
$length = strlen($rowtoparse);
$partialleft = substr($rowtoparse, 0, $pos2);
$partialright = substr($rowtoparse, $pos2);
$parsedrows[$fudgedindex] = $parsedrows[$fudgedindex] . $partialleft;
$fudgedindex = $fudgedindex + 1;
$parsedrows = '';
$parsedrows[$fudgedindex] = $parsedrows[$fudgedindex] . $partialright;
}
}
I keep getting undefined index after I increment $fudgedindex.
It's been a while since I've been on PHP, and I get the feeling that I'm either overthinking this and being a bit too procedural, or doing a head-slap error.
Any help appreciated! And once again, thanks for taking the time to help. =)
EDIT: Per the comments, here's what I'm aiming for...
$refinedlist[0]="Today I bought milk..Then I went to the "
[1]="store and bought even more food "
[2]="such as apples..I was happy..Then"
[3]=" I went to stackoverflow.com and asked this question "
[4]="to solve my problem.."
Result should be:
$parsedrows[0]="Today I bought milk"
[1]="Then I went to the store and bought even more food such as apples"
[2]="I was happy."
[3]="Then I went to stackoverflow.com and asked this question to solve my problem"
EDIT 2: The error is gone, so the initial issue is fixed. However, when I run this after:
foreach($parsedrows as $rowtoprint)
{
echo $rowtoprint . "<br>";
}
Only the last row shows up.