php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48836 Example for HTTP auth has bad regexp
Submitted: 2009-07-07 16:16 UTC Modified: 2009-07-08 08:21 UTC
From: mike at silverorange dot com Assigned: rquadling (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2009-07-07 16:16 UTC] mike at silverorange dot com
Description:
------------
The regular expression in the example on the HTTP authentication page (http://php.net/manual/en/features.http-auth.php) is incorrect.

It seems from the comments on the page, a lot of developers are running into problems trying to use the example.

Expected result:
----------------
The expression is correct. The subpattern for matching quoted values needs to be non-greedy so it doesn't capture the whole auth string.

Here's a cleaned up and commented version of the expression that works:

preg_match_all(
    '@
    (\w+)                 # name
    =
    (?:
      ([\'"])([^\2]+?)\2  # quoted value
      |
      ([^\s,]+)           # unquoted value
    )@x',
    $txt, $matches, PREG_SET_ORDER);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-08 08:21 UTC] rquadling@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 23:00:02 2026 UTC