Skip to content

Instantly share code, notes, and snippets.

@msng
Created March 23, 2012 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msng/2169763 to your computer and use it in GitHub Desktop.
Save msng/2169763 to your computer and use it in GitHub Desktop.
全角のみのチェックもうこれでいいんじゃないの
<?php
//Requires function is_hankaku() https://gist.github.com/2167287
function is_zenkaku($str, $encoding = null) {
if (is_null($encoding)) {
$encoding = mb_internal_encoding();
}
$len = mb_strlen($str, $encoding);
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($str, $i, 1, $encoding);
if (is_hankaku($char, true, true, $encoding)) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment