insertLineBreaks got " . $text;
$brString = "<br>";
$curPosition = 0;
$textPieces = explode($brString, $text);
$textPiecesLength = count($textPieces);
for ($i = 0; $i < $textPiecesLength; $i++) {
$curString = $textPieces[$i];
print "
text piece $i is $curString";
$lastInsertedBr = 0;
print "
curString length is " . strlen($curString);
while ((strlen($curString) - $lastInsertedBr) > $textSplitSize) {
print "
looking for spaces...";
// Start looking for spaces starting at $lastInsertedPos.
$maxInsertedPosition = $lastInsertedBr + $textSplitSize;
$lastSpacePos = $lastInsertedBr;
$oldLastSpacePos = $lastInsertedBr;
print "
begin: lastSpacePos is $lastSpacePos";
while (($lastSpacePos <= $maxInsertedPosition) && !($lastSpacePos === false)) {
$oldLastSpacePos = $lastSpacePos;
$lastSpacePos = strpos($curString, ' ', $lastSpacePos + 1);
print "
now lastSpacePos is $lastSpacePos";
}
if ($oldLastSpacePos == $lastInsertedBr) {
// This is a really long string that we can do nothing about,
// so lie.
print "
giving up";
// Just insert something at the next space.
if ($lastSpacePos === false) {
// There are no more spaces, so do nothing.
$oldLastSpacePos = -1;
} else {
$oldLastSpacePos = $lastSpacePos;
}
}
if ($oldLastSpacePos == -1) {
// Lie to make sure we don't do anything.
$lastInsertedBr = strlen($curString);
} else {
// Use $oldLastSpacePos
$curString = substr($curString, 0, $oldLastSpacePos) . $brString . substr($curString, $oldLastSpacePos+1);
print "
curString is now $curString";
$lastInsertedBr = $oldLastSpacePos + strlen($brString);
print "
lastInsertedBr is now $lastInsertedBr";
}
}
$textPieces[$i] = $curString;
}
print "
insertLineBreaks is returning " . implode($brString, $textPieces);
return implode($brString, $textPieces);
}
print "
running script...
"; #print "post[addmarker] is: " . $_POST["addmarker"]; #print "post[lat] is: " . $_GET["lat"]; #print "post[lat] is: " . $_GET["addLat"]; //if (isset($_POST["addmarker"])) { if (isset($_POST["lat"]) && ($_POST["lat"] != "NaN" && $_POST["lng"] != "NaN")) { // Lock the datakatrina.xml file. print "inside loop
"; $lockFileName = "data/marielock"; // TODO - add to appropriate thing. $fileName = "data/markers.xml"; $logFileName = "data/commentlog"; while (file_exists($lockFileName)) { usleep(250000); } print "got lock
"; $lockHandle = fopen($lockFileName, "w"); fwrite($lockHandle, "locked"); fclose($lockHandle); $fileContents = file($fileName); $numLines = count($fileContents); $fileContents[$numLines] = $fileContents[$numLines-1]; $fileContents[$numLines-1] = "