#31187 [Opn]: preg_match returning empty values

From: Date: Sun, 19 Dec 2004 20:31:17 +0000
Subject: #31187 [Opn]: preg_match returning empty values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-70639@lists.php.net to get a copy of this message
ID: 31187 User updated by: jackie at jdcdesigns dot com Reported By: jackie at jdcdesigns dot com Status: Open Bug Type: Regexps related Operating System: Apache PHP Version: 4.3.10 New Comment: please note that "Expected result" and "Actual Result" are inversed Previous Comments: ------------------------------------------------------------------------ [2004-12-19 21:28:43] 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" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31187&edit=1

« previous php.bugs (#70639) next »