Changing preg_match condition

66 views Asked by At

My function is changing $word_one (je/que je in j'/que j'), if $word_two begins with a vowel.

function FrenchCompoundTenses($word_one, $word_two) {
if(preg_match('~(.*)\bje$~ui', $word_one, $m) && preg_match('~^[aeéiou]~ui>', $word_two)) 
    return "<td class=\"text-right text-muted\">{$m[1]}j'</td>" . $word_two;               
else 
    return "<td class=\"text-right text-muted\">". $word_one ."</td>" . $word_two;
}  

For a similar function I have to change this part:

&& preg_match('~^[aeéiou]~ui>', $word_two)

It should worked, if $word_two begin with HTML code <u> or </td><td> and then a vowel is following.([aeéiou])

EDIT: $word_one comes from an array with pronoun and $word_two comes from a 2-dimensional array. $word_two are in this case two words.

example:

 $word_one= 'je' +   $word_two='aime'  =  j'aime 
 $word_one= 'tu' +   $word_two='aimes' = tu aimes 

desired output with this function:

 $word_one= 'je' +   $word_two='<u>aime' = j'aime (with html code between)
 $word_one= 'je' +   $word_two='</td><td>aime' = j'aime (with html code between)
1

There are 1 answers

4
Casimir et Hippolyte On BEST ANSWER

&& preg_match('~^h?(?:[aæàâeéèêëiîïoôœuûù]|y(?![aæàâeéèêëiîïoôœuûù]))~ui', strip_tags($word_two)) should solve the problem.

(I added an optional h at the begining since h is a silent h in french. I added too several accented vowels) and the y when not followed by another vowel.