php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39624 Regexp fails if there's more than 1 string to replace in the same line
Submitted: 2006-11-24 17:37 UTC Modified: 2006-11-24 17:53 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nino at recgr dot com Assigned:
Status: Not a bug Package: Regexps related
PHP Version: 5.2.0 OS: Windows XP SP2(with all patches)
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nino at recgr dot com
New email:
PHP Version: OS:

 

 [2006-11-24 17:37 UTC] 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> !

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-24 17:53 UTC] johannes@php.net
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

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 20 22:01:28 2024 UTC