- array_reverse: documentation ( source)
- preg_match_all: documentation ( source)
- explode: documentation ( source)
- strtolower: documentation ( source)
- join: documentation ( source)
<?php
$text = "А Анна упала на лапу Азора";
$words = explode(' ', $text);
foreach($words as &$word) {
$reverse_word = utf8_strrev($word);
if (strtolower($word) == strtolower($reverse_word)) {
echo $word . " - поллиндром\n";
} else {
echo $word . " - не поллиндром\n";
}
}
function utf8_strrev($str){
preg_match_all('/./us', $str, $ar);
return join('',array_reverse($ar[0]));
}