0

I'm having trouble matching â character in the string.

For example

if (preg_match("/C[â]mera/i", "Câmera Canon ")) // returns false

but

if (preg_match("/C[a]mera/i", "Camera Canon ")) // returns true

Any idea? why it's working with a but not with â?

Thanks

2
  • Have you checked you file encoding? Commented Dec 3, 2013 at 12:52
  • you mean .php file encoding? how do we set it? Commented Dec 3, 2013 at 12:58

2 Answers 2

3

If you are working with unicode strings (ie. UTF-8), you should use the u flag:

preg_match("/C[â]mera/iu", "Câmera Canon ")

u (PCRE_UTF8)

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

Sign up to request clarification or add additional context in comments.

Comments

1

Try something like this:

if (preg_match("/C[\pL00E2]mera/u", "Câmera Canon "))

1 Comment

This would match preg_match("/C[\pL00E2]mera/u", "Cemera Canon ") too f.ex.

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.