#19346 [Opn->Bgs]: preg_match() does not work for UTF-8
| From: | wez@php.net | Date: | Wed, 11 Sep 2002 14:48:28 +0000 |
| Subject: | #19346 [Opn->Bgs]: preg_match() does not work for UTF-8 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-19042@lists.php.net to get a copy of this message | ||
ID: 19346
Updated by: wez@php.net
Reported By: gamid@isayev.net
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: Mandrake 8.1
PHP Version: 4.3.2-dev
New Comment:
I meant 8bit instead of ascii.
This is not a problem with PHP but a problem with the pcre
library. If the pcre library doesn't support it, neither
does PHP; so if you don't like it, complain to the pcre
people and when they have implemented this feature we can
bundle it with PHP.
So, this is bogus again.
Previous Comments:
------------------------------------------------------------------------
[2002-09-11 08:51:02] gamid@isayev.net
But it does not make sense to specify UTF-8 in the pattern string if
subject string may have only ASCII, does it?
BTW, how I can specify UTF-8 characters in the pattern string?
Let say I need write pattern string which match to _any_ UTF-8 alphabet
character (like 'A-Za-z' for ASCII). How will this pattern string look
if [:alpha:] and \w do not work?
------------------------------------------------------------------------
[2002-09-10 18:47:30] wez@php.net
The manual says:
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.
So, it's only the pattern string that is treated as
utf-8; the subject string is still treated as a sequence
of ascii bytes.
I have to admit that I thought that the subject would
be treated as utf-8 too, but that is not the case.
So, this is "bogus" (it sounds so harsh) as far as PHP
is concerned, although this is a valid feature request;
it should be taken up with the pcre library people.
------------------------------------------------------------------------
[2002-09-10 17:31:33] gamid@isayev.net
BTW, it also does not work in PHP 4.3.2-dev,
PHP: 20020307
PHP Extension: 20020429
Zend Extension: 20020903
------------------------------------------------------------------------
[2002-09-10 17:30:08] gamid@isayev.net
<?
$name = "Test".utf8_encode("\xDC");;
echo "name = '$name'<BR>\n";
echo preg_match("/^[[:alpha:]]+$/u", $name);
echo "<BR>\n";
?>
The above snippet does not produce expected result.
According to documentation, preg_match() should return a true value,
but it returns false.
It looks as modifier 'u' does not work as it is described in the manual
( http://www.php.net/manual/en/pcre.pattern.modifiers.php
).
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19346&edit=1