Hm. Need help with my code. Complicated challenge!
1. Take a word.
2. Keep first letter of the word
3. Keep last letter of the word
4. Scramble letters in the middle
Okay, I've done that in my original code. However, I'm having problems implementing the next step.
1. Define an array of clumped characters. (e.g. "en", "ing", "at", "xtra")
2. Repeat the original steps, except while scrambling the letters, if there are characters defined within the clumped array in the original word, those characters cannot be separated. I've attempted it and failed (Only spent about 1-2 hours) and I'll try again later, but I want to use this for a new project I'm working on and was wondering if anyone else could think of a solution. Also, after this step, I plan to implement the following:
1. Take word and remove first and last letters. (clumped letters count as ONE letter)
2. Count the remaining letters
3. Group the remaining letters by every 3 letters (again, clumped letters count as ONE letter)
Final Effect: Words should be readable, but misspelled. They should also have a "random" element to it so that if I scrambled a sentence, I would have to press "refresh" many times before I ever get the same result twice. (The ultimate object is the misspell the words, but keep them readable to the human brain. Look up typoglycemia)
Here's my failed attempt. (got stuck on part 2 which I thought would be harder than part 3.)
<?php
$textToScramble = stripslashes($_POST["textToScramble"]);
$clumpArray = array("er","ing","xtr","an","or","es"); //define the values for the clumped letters
$clumpArraySize = count($clumpArray); //Count the clump array size
for($a = 0; $a < $clumpArraySize; $a++){ //Replace all words found in the preserve array
$textToScramble = str_replace($clumpArray[$a], "|".$clumpArray[$a]."|", $textToScramble); //get words
}
$textArray = explode(" ", $textToScramble); //split up the words by spaces
$textArraySize = count($textArray);
$completeArray = array();
for($i = 0; $i < $textArraySize; $i++){ //Loop through every word in the text.
$scrambleArray = array();
$currentString = $textArray[$i]; //Get a word
$toggle = 1;
while (isset($currentString[$b])) { //While the letters are defined
if($currentString[$b] == "|"){ //check to see if letter is there
$toggle = $toggle * (-1);
}
if($toggle == 1){
if($currentString[$b] != "|"){
$currentLetter = $currentString[$b];
}
} else {
if($currentString[$b] != "|"){
$currentLetter .= $currentString[$b];
}
}
if($toggle == 1){
array_push($scrambleArray, $currentLetter);
$currentLetter = "";
}
$b++;
}
$scrambleArraySave = $scrambleArray; //copy the array
$scrambleArrayCount = count($scrambleArray);
unset($scrambleArray[$scrambleArrayCount-1]); //remove last character
unset($scrambleArray[0]); //remove first character
shuffle($scrambleArray); //shuffle remaining
$scrambledWord = $scrambleArraySave[0]; //Get first letter
for($d = 0; $d < $scrambleArrayCount; $d++){ //concencate the scrambled letters on to the first letter of the original word.
$scrambledWord .= $scrambleArray[$d];
}
if ($scrambleArrayCount - 2 >=0){
$scrambledWord .= $scrambleArraySave[$scrambleArrayCount - 1]; //Get last letter and attach it.
}
array_push($completeArray, $scrambledWord);
}
foreach ($completeArray as $word) { //display each scrambled word after another.
echo $word." ";
}
?>






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None














Help