I am trying to find out the best way of going about string replacement with multiple collations.
I have a sentence which is inserted by user, i have an array which of all the miss-spelled words in that sentence and their potential corrections.
$sentence = 'i want to recovary my vehical from the cabs';
I want to display the following:
- i want to recovery my vehicle from the cabs
- i want to recover my vehicle from the cabs
- i want to revary my vehicle from the cabs
Code so far:
$element = array(
"vehical" => array('vehicle'),
"recovary" => array('recovery', 'recover', 'revary')
);
$sentence = 'i want to recovary my vehical from the cabs';
foreach($element as $i => $val){
echo $i;
}
EDIT: Expanded another scenario:
What would happen if there was more than one variation in the top array.
"vehical" => array('vehicle', 'vehiclesy', 'whatever'),
"recovary" => array('recovery', 'recover', 'revary')
- i want to recovery my vehicle from the cabs
- i want to recovery my vehiclesy from the cabs
- i want to recovery my whatever from the cabs
- i want to recover my vehicle from the cabs
- i want to recover my vehiclesy from the cabs
- i want to recover my whatever from the cabs
- i want to revary my vehicle from the cabs
- i want to revary my vehiclesy from the cabs
- i want to revary my whatever from the cabs