php - How to check if two last characters in string correspond to array 1 + array 2 -



php - How to check if two last characters in string correspond to array 1 + array 2 -

i don't know how find this.

basically, want script check word, example:

'word'

i have 2 arrays:

$vowels=array("a","o","i","u","á","ó","í","ú","é","ō","ē"); $consonants=array("b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","z");

the code should check if lastly 2 characters of string contain combination of vowel + consonant.

not consonant + consonant or consonant + vowel. seems harder looks it. check lastly 2 characters use:

$lastletters= substr($word['word'], -2);

the problem don't know how check word array in substr.

if($lastletters="$vowels"."$consonants")

doesn't work, and

if($lastletters=$vowels.$consonants)

simply doesn't work.

you can utilize regular look that.

$vowelsstr = implode('', $vowels); $constr = implode('', $consonants); if (preg_match('/['.$vowelsstr.']['.$constr.']$/', $word)) { // found }

php arrays substr

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -