Search code examples
phphtmlpreg-match

Weird result in php


Why the output of this code is "true" ?

<?php

if (preg_match("/^[Ī]+$/", "ê")) {
    die("true");
} else {
    die("false");
}

?>

The result should be false not true!


Solution

  • Your strings are unicode, so if you want the preg_match to work on a unicode string you should add the u modifier:

    if (preg_match("/^[Ī]+$/u", "ê")) {