On like 20 I keep getting a memory leak. I'm sure I'm just not seeing what the problem is but was hoping someone with fresh eyes could tell me where I'm going wrong at.
--inside of the work, suppose to take a sentence and after every word with a comma, reverse the word without moving it's place in the sentence.
function bassAckwards($input)
{
//$inputLen = strlen($input);
$stringEnd = 0;
$findme = ',';
$flag1 = true;
$tempOffset = 0;
$string = "";
//Start loop, as long as flag is true
while($flag1 == true){
//find position of next ","
$pos = strpos($input, $findme, $tempOffset);
//If $pos is null end loop and return string.
if($pos == false){
$flag1 = false;
}
else{
//$pos is not null so create inner loop and add to string
for($reverse = $pos--; $reverse > $stringEnd; $reverse--){
$string = $string . substr($input, $reverse); // < ------ TempStr will add in substr, which will be added to $string
}
}
$stringEnd = $pos;
$tempOffset = $pos + 1;
}
return $string;
}
print bassAckwards("Php,Cookies,Arrays,Mysql,LAMP");