#39624 [Opn->Bgs]: Regexp fails if there's more than 1 string to replace in the same line

From: Date: Fri, 24 Nov 2006 17:53:33 +0000
Subject: #39624 [Opn->Bgs]: Regexp fails if there's more than 1 string to replace in the same line
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105423@lists.php.net to get a copy of this message
ID: 39624 Updated by: johannes@php.net Reported By: nino at recgr dot com -Status: Open +Status: Bogus Bug Type: Regexps related Operating System: Windows XP SP2(with all patches) PHP Version: 5.2.0 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php . Previous Comments: ------------------------------------------------------------------------ [2006-11-24 17:37:37] nino at recgr dot com Description: ------------ A Regex command normally replaces (using preg_replace), but only when there is just one string to match in line. Otherwise it gives some unexpected(weird) code. I've tried some *similar* codes, and they are all buggy in the same way. Reproduce code: --------------- $s = preg_replace("#\[url\=(.*)\](.*)\[\/url\]#i", "<a href=\"$1\" target=\"_blank\">$2</a>", $s); Then, for instance, a $s would be: EXAMPLE #1 If you dunno, or have no idea, you can try looking up [url=http://www.here.com]here[/url]. EXAMPLE #2 If you dunno, or have no idea, you can try looking up [url=http://www.here.com]here[/url] or [url=http://www.anotherhere.com]here[/url] ! Expected result: ---------------- EXAMPLE #1 is fine, but I expect for EXAMPLE #2 to get this: If you dunno, or have no idea, you can try looking up <a href="http://www.here.com" target="_blank">here</a> or <a href="http://www.anotherhere.com">here</a> ! Actual result: -------------- EXAMPLE #1 works fine, I get this: If you dunno, or have no idea, you can try looking up <a href="http://www.here.com" target="_blank">here</a>. EXAMPLE #2 doesn't work fine, I get this: If you dunno, or have no idea, you can try looking up <a href="http://www.here.com]here[/url] or [url=http://www.anotherhere.com" target="_blank">here</a> ! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39624&edit=1

« previous php.bugs (#105423) next »