php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61775 Preg_match does not support unicode.
Submitted: 2012-04-19 17:07 UTC Modified: 2012-04-20 11:07 UTC
From: asersz at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.4.0 OS: MacOS Lion 10.7.2
Private report: No CVE-ID: None
 [2012-04-19 17:07 UTC] asersz at gmail dot com
Description:
------------
I am not good at english.

A warning: preg_match(): Compilation failed: unknown option bit(s) set at offset 
0

OS: MacOSX Lion 10.7.2
Web Server: apache 2
PHP : 5.4.0
PCRE (Perl Compatible Regular Expressions) Support: enabled
PCRE Library Version: 8.02 2010-03-19

By the way: the php 5.4.0 released is stable or not ?

thanks.

Test script:
---------------
<?php
$r='/^(?P\w+)\/(?P\d+)\/$/u';
var_dump(preg_match($r,'test'));

Expected result:
----------------
What does the warning mean ?

The preg_match should be return 0 without warnings.

Actual result:
--------------
Warning: preg_match(): Compilation failed: unknown option bit(s) set at offset 0 
in /Users/zhangyowei/Web/lieqee/test.php on line 4
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-19 21:09 UTC] cataphract@php.net
-Status: Open +Status: Not a bug
 [2012-04-19 21:09 UTC] cataphract@php.net
Your expression is wrong. Version 8.02 of PCRE, which you're using, gives that rather cryptic error, but more recent versions, including the one bundled with PHP say:

Warning: preg_match(): Compilation failed: unrecognized character after (?P at offset 4 in - on line 3

Probably you want something like:

<?php
$r='/^(?P<foo>\w+)\/(?P<bar>\d+)\/$/u';
var_dump(preg_match($r,'test/3423/',$m), $m);
 [2012-04-20 03:11 UTC] asersz at gmail dot com
But this expression works fine in the PHP 5.3.x (and 5.2.x).

And works fine without the Modifier "u".

Why does not works fine in PHP 5.4?
 [2012-04-20 04:17 UTC] asersz at gmail dot com
Warning: preg_match(): Compilation failed: unknown option bit(s) set at offset 0 
in /Users/zhangyowei/Web/lieqee/test.php on line 5
bool(false) NULL

Your expression trigger a warning too.
 [2012-04-20 07:23 UTC] cataphract@php.net
Works here:

glopes@nebm:~/php/php-src$ php -v
PHP 5.3.10-dev (cli) (built: Feb  2 2012 11:31:13)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
glopes@nebm:~/php/php-src$ php
<?php
$r='/^(?P<foo>\w+)\/(?P<bar>\d+)\/$/u';
var_dump(preg_match($r,'test/3423/',$m), $m);
int(1)
array(5) {
  [0]=>
  string(10) "test/3423/"
  ["foo"]=>
  string(4) "test"
  [1]=>
  string(4) "test"
  ["bar"]=>
  string(4) "3423"
  [2]=>
  string(4) "3423"
}

I suspect that, if anything, this has been an PCRE change. Try recompiling PHP with the bundled PCRE (--with-pcre-regex=BUNDLED, if I'm not mistaken).
 [2012-04-20 07:26 UTC] cataphract@php.net
Sorry, that was 5.3, but I can confirm it works with 5.4 too (PCRE version 8.12 2011-01-15).
 [2012-04-20 11:07 UTC] asersz at gmail dot com
I will recompile my PCRE and PHP.

But I confirm my expression works fine in PHP 5.3.6.

This expression was default configuration for class CUrlManager in Yii framework. 
After I upgrade my PHP 5.3.6 to 5.4.0, the warning was triggered.

Same bug reporting here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=659478

Thanks :-D
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 16:01:29 2024 UTC