Last active
December 23, 2015 19:59
-
-
Save mogya/6686275 to your computer and use it in GitHub Desktop.
文字列がひらがなを含むかどうかのチェック:駄目な例
see: http://blog.mogya.com/2013/09/php-preg-match-mb-ereg.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$output = ''; | |
$comment = 'あいうえお'; | |
if (isset($_POST['comment'])){ | |
$comment = $_POST['comment']; | |
if (preg_match("/[あ-ん]/", $comment)) | |
{ | |
$outputs = Array(); | |
$outputs[] = 'MATCH'; | |
$outputs[] = 'ret:'.preg_match("/[あ-ん]/", $comment, $match,PREG_OFFSET_CAPTURE); | |
$outputs[] = var_export($match,TRUE); | |
$outputs[] = 'mb_regex_encoding:'.mb_regex_encoding(); | |
$outputs[] = 'mb_internal_encoding:'.mb_internal_encoding(); | |
$output = join("\n",$outputs); | |
}else{ | |
$output = 'NOT MATCH'; | |
} | |
} | |
?> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
</head> | |
<html> | |
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > | |
<input type="text" name="comment" value="<?php echo $comment; ?>" /> | |
<input type="submit" value="test" /> | |
</form> | |
結果: | |
<textarea><?php echo $output; ?> | |
</textarea> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment