It's very easy to write in PHP using strlen
and strpos
functions:
function isRotation($string1, $string2) {
return strlen($string1) == strlen($string2) && (($string1.$string1).strpos($string2) != -1);
}
I don't know what strpos
uses internally, but if it uses KMP this will be linear in time.