#23903 [Opn->Asn]: preg_replace incorrect output with *
| From: | sniper@php.net | Date: | Fri, 06 Jun 2003 08:05:06 +0000 |
| Subject: | #23903 [Opn->Asn]: preg_replace incorrect output with * | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-41321@lists.php.net to get a copy of this message | ||
ID: 23903
Updated by: sniper@php.net
Reported By: mnilsson at bowesnet dot com
-Status: Open
+Status: Assigned
-Bug Type: *Regular Expressions
+Bug Type: PCRE related
Operating System: linux 2.4.18
PHP Version: 4.3.2
-Assigned To:
+Assigned To: andrei
New Comment:
Andrei, is this documentation issue or real bug? :)
Previous Comments:
------------------------------------------------------------------------
[2003-05-30 15:12:29] elmicha@php.net
Smaller example:
echo preg_replace ("/(.*)/", "http://\$1",
"abc"),"\n";
Output: http://abchttp://
This doesn't look correct to me.
However, your search pattern doesn't look very reasonable - the normal
way to prepend a string to another string is the "." operator:
$bannerad_url = 'http://' .
$_POST['bannerad_url'];
------------------------------------------------------------------------
[2003-05-30 13:08:35] mnilsson at bowesnet dot com
PROBLEM: preg_replace does not return the proper value with
a * in the regular expression.
INPUT: $_POST['bannerad_url'] = 'www.canoe.ca';
PROCESS CODE:
$_POST['bannerad_url'] = trim($_POST['bannerad_url']);
if (preg_match ("/^http:\/\/(.*)/i",
$_POST['bannerad_url']) > 0)
$bannerad_url = $_POST['bannerad_url'];
else
$bannerad_url = preg_replace ("/(.*)/", "http://\$1",
$_POST['bannerad_url']);
OUTPUT: echo $bannerad_url; -------> http://
www.canoe.cahttp://
FIX:
INPUT: $_POST['bannerad_url'] = 'www.canoe.ca';
PROCESS CODE:
$_POST['bannerad_url'] = trim($_POST['bannerad_url']);
if (preg_match ("/^http:\/\/(.+)/i",
$_POST['bannerad_url']) > 0)
$bannerad_url = $_POST['bannerad_url'];
else
$bannerad_url = preg_replace ("/(.+)/", "http://\$1",
$_POST['bannerad_url']);
OUTPUT: echo $bannerad_url; -------> http://www.canoe.ca
NOTES:
I was able to reproduce this several times. It seems to be
related to the *, but replacing it with a + solves the
problem. Thanks.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23903&edit=1