Skip to content

Instantly share code, notes, and snippets.

@kazz187
Created May 25, 2015 08:43
Show Gist options
  • Save kazz187/bd1a0091cfbf71024c9f to your computer and use it in GitHub Desktop.
Save kazz187/bd1a0091cfbf71024c9f to your computer and use it in GitHub Desktop.
<?php
$str = "よのなかねかおかおかねかなのよ";
var_dump(kaibun_check($str));
function kaibun_check($str) {
$char_code = 'utf8';
$length = mb_strlen($str, $char_code);
for ($i = 0; $i < $length / 2; $i++) {
if (mb_substr($str, $i, 1, $char_code) !== mb_substr($str, $length - $i - 1, 1, $char_code)) {
return false;
}
}
return true;
}
@kazz187
Copy link
Author

kazz187 commented May 25, 2015

% php kaibun_check.php
bool(true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment