Okay, I became a little obsessed with this and decided to have a go (hey, it's Friday evening).
As I noted in the comment above, you want to generate a new word variation for each individual letter change - including letters that occur more than once. Another tricky consideration is multibyte characters.
What follows is an attempt an an answer that is probably pretty sub-optimal but hopefully gets the job done... I'm sure there are many ways to improve this but it's a start that you might be able to iterate on:
<?php
// this solution assumes UTF-8 config settings in php.ini
// setting them with ini_set() seems to work also but ymmv
ini_set('default_charset', 'UTF-8');
ini_set('mbstring.internal_encoding', 'UTF-8');
function getWordReplacements($word, $replacements) {
// $results... add the original
$results = array($word);
// multibyte split of $word
// credit: http://stackoverflow.com/a/2556753/312962
$chars = preg_split('//u', $word, -1, PREG_SPLIT_NO_EMPTY);
// we will iterate over the chars and create replacements twice,
// first pass is a forward pass, second is a reverse pass
// we need a copy of the $chars array for each pass
$forwardPass = $chars;
$reversePass = $chars;
// how many chars in the word?
$length = count($chars);
// we'll store the index of the first character
// that has a copy in the $replacements list for later
$first = null;
// first pass... iterate!
for ($i = 0; $i < $length; $i++) {
// is the current character in the $replacements list?
if (array_key_exists($chars[$i], $replacements)) {
// save the index of the first match
if (is_null($first)) {
$first = $i;
}
// replace the found char with the translation
$forwardPass[$i] = $replacements[$forwardPass[$i]];
// flatten the result and save it as a variation
$results[] = implode($forwardPass);
}
}
// second pass... same as the first pass except:
// * we go backwards through the array
// * we stop before we reach the $first index, to avoid a duplicate
// entry of the first variation saved in the first pass...
for ($j = ($length - 1); $j > $first; $j--) {
if (array_key_exists($chars[$j], $replacements)) {
$reversePass[$j] = $replacements[$reversePass[$j]];
$results[] = implode($reversePass);
}
}
// return the results
return $results;
}
// test with a subset replacement list
$list = [
'ç' => 'c',
'ğ' => 'g',
'ş' => 's',
'i' => 'ı',
];
// a couple of examples
$r1 = getWordReplacements('pişir', $list);
$r2 = getWordReplacements('ağaç', $list);
var_dump($r1, $r2);
Yields:
array (size=6)
0 => string 'pişir' (length=6)
1 => string 'pışir' (length=7)
2 => string 'pısir' (length=6)
3 => string 'pısır' (length=7)
4 => string 'pişır' (length=7)
5 => string 'pisır' (length=6)
array (size=4)
0 => string 'ağaç' (length=6)
1 => string 'agaç' (length=5)
2 => string 'agac' (length=4)
3 => string 'ağac' (length=5)
Hope this helps :)