elseif(($_temp == "]")) //then this is not the first copy}
{
$_len= strlen($baseFil);
$startBrackedPosition = strrpos($baseFil , "["); //find where the last bracket is
$startBrack = $baseFil[($startBrackedPosition)];
$offset= abs($startBrackedPosition -$closeBrackedPosition)+1//offset between brackets
$closeBracketIndex = abs(strlen($baseFil))-abs($offSet);
$_tempCharTwo = $baseFil[($closeBracketIndex-1)];
$howManyDigits = abs(strlen($baseFil)- $startBrackedPosition ) -2;
if( ($startBrack == "[") )
{
$actualNumber;
for($i= ($startBrackedPosition+1); $i < ($startBrackedPosition + $howManyDigits+1) ;$i++)
$actualNumber++ ;//increase the number so that the suffix is the next one
{
$dig = $baseFil[$i];
//note the easy-to-miss string concatenation in the next line!
$actualNumber .="$dig";
}
$suffix= "[$actualNumber]";
$offset = $_len-($howManyDigits +2 );
$new = substr_replace($baseFil, $suffix, $offset);
}
return $new; //this is the new string with appended suffix
<?php
$renameFile = generateCopyStringName($filesOriginalName);
echo "file's new copied name is $renameFile";
?>