Skip to content

Instantly share code, notes, and snippets.

@mogya
Last active December 23, 2015 19:59
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 mogya/6686275 to your computer and use it in GitHub Desktop.
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
<?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