php - empty range in char class


I have this script


$yomi = 'アイウエオャュョハ゛ヒ゜';

if (mb_ereg('^[ヲ-゜]+$', $yomi)) {
    return true;
return false;

When I run it I get a warning:

[Warning]: mb_ereg(): mbregex compile err: empty range in char class

I googled but can't find a solution. Help please.




If you are looking for a half-width katakana regex, you can use the following validation:

preg_match('~^[ァ-ン゙゚]*$~u', $yomi, $matches)

See the regex demo

IDEONE demo:

$re = "/^[ァ-ン゙゚]*$/u"; 
$yomi = "アイウエオャュョハ゛ヒ゜";
$yomi2 = "カタカナ"; 
if (preg_match($re, $yomi, $matches)) {
    echo "$yomi is valid!\n";
if (preg_match($re, $yomi2, $matches)) {
    echo "$yomi2 is valid!";

Output is onlyカタカナ is valid!.

People are also looking for solutions to the problem: php - PDF to Word at LAMP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.