This site works best with JavaScript enabled!

Description: Text Converter - Jumble Letters

Converter jumble letters

This article describes how the text converter "Jumble Letters" works. In this converter, you can enter a text which is then converted into a text with jumbled letters.

Text Converter "Jumble Letters"

Click here to go to the converter described below.

Fascinating: Brain can understand texts with jumbled letters

Can you read the text above? Probably - even if there may be a few words that you can not decipher right away.

In the sample text above, the middle letters have been randomly swapped; the first and last letters have remained unchanged in their position. When you think about it, it's fascinating what our brain can do.

As it is very difficult to create such a text manually, so to jumble the individual letters by hand, there exists this converter. So you just have to enter the original text and convert it.

How does this converter work?

In principle, this converter uses regular expressions to search for all words with at least four letters, because with fewer letters there is nothing to jumble, of course, since the first and the last letter always remain unchanged. The search for these words is done using the PHP callback function preg_replace_callback():

1
$output_text = preg_replace_callback("#([A-ZÄÖÜß])([A-ZÄÖÜß]{2,})([A-ZÄÖÜß])#ui", "function_convert", $input_text);

The extracted words are then processed using the self-created function function_convert($matches) and finally are replaced by their return value. Depending on the selected method, different commands are executed. If the middle letters shall be arranged in a random order, this is done as follows:

1
2
3
4
5
$chars	= preg_split('##u', $matches[2]);		// Split string to array
shuffle($chars);					// Mix array randomly
$output	= $matches[1].implode($chars).$matches[3];	// Merge individual letters

return $output;

With preg_split() the inner string of the word (excluding the first and the last letter) is split into individual elements and stored in an array. In principle, there are more suitable functions for this task, but most of them do not work with the german umlauts Ä, Ö and Ü.

For the method Reversed Order, the array is simply reversed instead of a random mixing:

1
2
3
4
5
$chars	= preg_split('##u', $matches[2]);		// Split string to array
array_reverse($chars);					// Reverse array
$output	= $matches[1].implode($chars).$matches[3];	// Merge individual letters

return $output;

When the letters shall be sorted in ascending alphabetical order, we have to replace all the umlauts and the ß after splitting the string:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$arr_replaced 	= array();
$sorted_list	= array();
$chars 		= preg_split('##u', $matches[2]);
$search		= array("#Ä#u", "#ä#u", "#Ö#u", "#ö#u", "#Ü#u", "#ü#u", "#ß#u");
$replace	= array("Ae", "ae", "Oe", "oe", "Ue", "ue", "ss");

$arr_replaced 	= preg_replace($search, $replace, $chars);	// Replace chars

natcasesort($arr_replaced);	// Sort in natural order

foreach($arr_replaced as $key => $value) $sorted_list[] = $chars[$key];

$output	= $matches[1].implode($sorted_list).$matches[3];

return $output;

For a descending alphabetical order, just add the following code into line 12:

1
$sorted_list = array_reverse($sorted_list);
Share this page
Posted on 22.02.2018 | Last modified on 24.05.2018