Following your example "carn? Ati? On":
You can split a word / string into an array by "?" then the last character of each line in the array will be an optional character:
[0] => carn
[1] => ati
[2] => on
You can then create two separate capabilities (i.e. with and without this last character) for each element in the first array and map these permutations to another array. Please note that the last element should be ignored for the above conversion, since it does not apply. I would do this in the form:
[0] => [carn, car]
[1] => [ati, at]
[2] => [on]
Then I will iterate over each element in the auxiliary arrays to calculate all the different combinations.
If you're stuck with this process, just post a comment.
tenub source
share