Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix preg_match(): Compilation failed at wp-db.php on line 1657

Discussion in 'Misc WordPress Requests' started by RWall, Nov 17, 2017.

  1. RWall

    Guest

    preg_match(): Compilation failed at wp-db.php on line 1657, by RWall

    After updating to V4.9, I had this error message on every page:

    Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 4 in [host url]/website/wp-includes/wp-db.php on line 1657

    And slightly more on the dashboard (cut off by the theme):

    …mpilation failed: unrecognized character after (?< at offset 4 in [host url]/website/wp-includes/wp-db.php on line 1657

    Warning: Cannot modify header information – headers already sent by (output started at [host url]/website/wp-includes/wp-db.php:1657) in [host url]/website/wp-admin/includes/misc.php on line 1114

    Can anyone suggest the cause and the fix?
    I see someone else asked about exactly the same error message at WordPress.com. I’ve rolled back to V4.8.3 in the meantime, but plugins, theme & content are all the same, all remained in place and not reloaded.

    preg_match(): Compilation failed at wp-db.php on line 1657
     
    #1
  2. Mike G

    New Member

    Joined:
    Jan 17, 2018
    Messages:
    1
    Likes Received:
    0
    I just ran into this problem too, but only on a site hosted in one particular place - sites I have hosted elsewhere are working fine. The error is from a regex using named captures. My best guess is that my host (and yours) are using an old PCRE library which doesn't support named captures.

    Your best bet is to complain to the host and ask them to update. But, in the mean time, you can work around it yourself by editing lines 1646 to 1665 of wp-db.php (full path is in your error message) as follows:

    PHP:
           // We need to check for an IPv6 address first.
           // An IPv6 address will always contain at least two colons.
           
    if ( substr_count$host':' ) > ) {
               
    //$pattern = '#^(?:\[)?(?<host>[0-9a-fA-F:]+)(?:\]:(?<port>[\d]+))?#';
               
    $pattern '#^(?:\[)?([0-9a-fA-F:]+)(?:\]:([\d]+))?#';
               
    $is_ipv6 true;
           } else {
               
    // We seem to be dealing with an IPv4 address.
               //$pattern = '#^(?<host>[^:/]*)(?::(?<port>[\d]+))?#';
               
    $pattern '#^([^:/]*)(?::([\d]+))?#';
           }

           
    $matches = array();
           
    $result preg_match$pattern$host$matches );

           if ( 
    !== $result ) {
               
    // Couldn't parse the address, bail.
               
    return false;
           }
           
    $matches['host'] = $matches[1];
           
    $matches['port'] = $matches[2];
           
    $host '';
    The two commented out //$pattern lines are the originals, and the replacements (which don't use named captures) are below. I've then added two lines at the end to assign $matches['host'] and $matches['port'] (which would be done automatically from the named captures). This provides the original functionality without using the named captures feature, and has resolved the error messages for me. (The second error message, regarding headers having already been sent, occurs purely because the first error message has been printed and throws things off - fixing that therefor resolves both.)
     
    #2

Share This Page

Monarch Social Sharing Plugin