php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81296 A question about square bracket matching
Submitted: 2021-07-26 03:32 UTC Modified: 2021-07-26 03:37 UTC
From: 958268052 at qq dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 8.0.8 OS: Ubuntu18.04
Private report: No CVE-ID: None
 [2021-07-26 03:32 UTC] 958268052 at qq dot com
Description:
------------
I executed this test script below, redirecting the result to a file, and I got an execution result of "Â".
When I execute it on other regular expression engines like java and python using the same regular expression and string, they both result in "£", unlike PHP. I don't understand why PHP has such a different result, is this a special implementation of the PHP regular expression engine or a defect in the engine?

Test script:
---------------
<?php
function matchTest($reg,$str){
    preg_match($reg,$str,$r);
    if (empty($r)) {
        return "";
    }   
        else{
    return $r[0];
    }
}
$regex = "/[£]/";
$testString = "£";
$result = matchTest($regex, $testString);
print_r($result);
?>

Expected result:
----------------
£

Actual result:
--------------
Â

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-26 03:37 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: *Regular Expressions +Package: PCRE related
 [2021-07-26 03:37 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Use the /u flag to turn on UTF-8 support.
https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
 [2021-07-26 14:19 UTC] 958268052 at qq dot com
I've understood what the problem is, thanks for your prompt answer and help!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC