What I've got up to now. Might be incorrect, Correct me if I am wrong:
Problems of the above code:
Regexp functions beginning with "ereg" implement a basic set of Regexp functionality. "mb_ereg_search" seems to be the same. So although we could have UTF-8 characters directly inside the patterns (I checked it with one pattern and worked for me) but what I wanted to do above isn't possible with mb_ereg_search.
What I should have done:
For better functionality we should use functions starting with "preg" (PCRE library), which are Perl-Compatible. So I should have:
$pattern="/\x{0061}/u"; in a function like "preg_match" or "preg_match_all".
You could use one or two backslashes, it dosn't matter, because both cases put the same string of "/\x{0061}/u" inside the Pattern argument of the function.
"u" at the end is is a Pattern Modifier by which pattern strings are treated as UTF-8.
So now the code should look like this:
<?php
$string = "a";
$pattern="/\x{0061}/u";
if (preg_match($pattern, $string, $matches)) {
echo 'Pattern FOUND.<br>';
}else {
echo 'Pattern NOT found.<br>';
}
?>
Outoput: Pattern FOUND.
More details:
PCRE library: Beginning with PHP 4.2.0 its functions are enabled by default. The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.
u (PCRE_UTF8) Modifier: This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32.
Ref:
PHP manual: "Regular Expression Functions (Perl-Compatible)"; "Pattern Modifiers"
PCRE man page
Perl Doc
RegexBuddy Regexp help