1

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";
}

?>
4
  • Your regex is confusing. What do you want to do? Commented Feb 22, 2017 at 12:27
  • I have match code something like in the string but they varies everytime Commented Feb 22, 2017 at 12:32
  • You can simplify it to [0-9*+=\-#@×?]{2,3}(?:[ \[\]().]{1,3}[0-9*+=\-#@×?]{2,3}){4} Commented Feb 22, 2017 at 12:34
  • @chris85 I will try that Commented Feb 22, 2017 at 12:42

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.