|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31187 preg_match returning empty values
Submitted: 2004-12-19 21:28 UTC Modified: 2004-12-19 21:39 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jackie at jdcdesigns dot com Assigned:
Status: Not a bug Package: Regexps related
PHP Version: 4.3.10 OS: Apache
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jackie at jdcdesigns dot com
New email:
PHP Version: OS:


 [2004-12-19 21:28 UTC] jackie at jdcdesigns dot com
When using preg_match or, preg_match all, it seems to be adding the array key as the value, instead of the matched value for instance, instead only the first match, 

This problem does NOT exist on version 4.3.9

Reproduce code:
$string='<a href="">Some Text</a>';

		preg_match_all('/<\s*a\s*href="([^\"]+)"\s*>([^>]*)<\/a>/i', $lines, $main_array, PREG_SET_ORDER);
		foreach($main_array as $main_code){
			$url = $main_code[1];
			$text = $main_code[2];
			echo "$url $text\n";

Expected result:
if $match[1] through  $match[4] equals "abc"

$match[1] returns "0"
$match[2] returns "1"
$match[3] returns "2"
$match[4] returns "3"

Actual result:
if $match[1] through  $match[4] equals "abc"

$match[1] should return "abc"
$match[2] should return "abc"
$match[3] should return "abc"
$match[4] should return "abc"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-19 21:31 UTC] jackie at jdcdesigns dot com
please note that 
"Expected result"  and "Actual Result" are inversed
 [2004-12-19 21:39 UTC]
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Nov 30 17:01:30 2023 UTC