Reputation: 679
Here is my code. I am trying to match this string with my regex but it fails everytime on my local xampp server and my dedicated server. Surprsingly when i test this on regex101 it works there somehow. Why ??
<?php
$str = "80 ×× ×× ×× ×× ××
×× ×× 91 94 ×× ××
";
echo strlen($str);
if (preg_match("/[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}/", $str)) {
echo "ok";
}else{
echo "no mto";
}
?>
Upvotes: 1
Views: 629
Reputation: 42885
You need to use the u
modifier to enable the unicode mode for regular expressions, since that ×
character in subject and pattern is not within the ASCII character range. Note the trailing /u
in the pattern definition:
<?php
$str = <<<EOT
80 ×× ×× ×× ×× ××
×× ×× 91 94 ×× ××
EOT;
if (preg_match("/[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}/u", $str)) {
echo "ok";
} else {
echo "no mto";
}
The output obviously is:
ok
Upvotes: 3