Hi all,
I'm trying to find all possible combinations of a word, and have certain letters replaced.
So, I have the following code:
<form name="search" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="searchterm" />
<input type="submit" value="Submit"/>
</form>
<?php
function pset($array) {
$results = array(array());
foreach ($array as $element)
foreach ($results as $combination)
array_push($results, array_merge(array($element), $combination));
return $results;
}
$searchterm = $_POST["searchterm"];
$search = array(
array("t","7"),
array("e","3")
);
$searchpowerset=pset($search);
foreach($searchpowerset as $a)
{
$newterm = str_replace($a[0][0],$a[0][1],$searchterm);
echo $newterm . "<br/>";
}
?>
The input for this from the form would be: peter
I would expect the output to include:
p3t3r
p373r
At the moment it's returning:
peter
pe7er
p3t3r
p3t3r
The repetitons aren't an issue as I can get rid of those easily, but I need to be able to have all replacements work on each cycle through.
Thanks in advance.