php.net |  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
Votes:1
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 + 18 = ?
Subscribe to this entry?

 
 [2004-12-19 21:28 UTC] jackie at jdcdesigns dot com
Description:
------------
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="http://www.example.com">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";
		}
print_r($main_array);

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"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] derick@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 15:01:31 2024 UTC