#39624 [NEW]: Regexp fails if there's more than 1 string to replace in the same line
| From: | nino at recgr dot com | Date: | Fri, 24 Nov 2006 17:37:37 +0000 |
| Subject: | #39624 [NEW]: Regexp fails if there's more than 1 string to replace in the same line | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-105422@lists.php.net to get a copy of this message | ||
From: nino at recgr dot com
Operating system: Windows XP SP2(with all patches)
PHP version: 5.2.0
PHP Bug Type: Regexps related
Bug description: Regexp fails if there's more than 1 string to replace in the same line
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 bug report at http://bugs.php.net/?id=39624&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39624&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39624&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39624&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39624&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39624&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39624&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39624&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39624&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39624&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39624&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39624&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39624&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39624&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39624&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39624&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39624&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39624&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39624&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39624&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39624&r=mysqlcfg