From:             mnilsson at bowesnet dot com
Operating system: linux 2.4.18
PHP version:      4.3.2
PHP Bug Type:     *Regular Expressions
Bug description:  preg_replace incorrect output with *

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 bug report at http://bugs.php.net/?id=23903&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=23903&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=23903&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=23903&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=23903&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=23903&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=23903&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=23903&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=23903&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=23903&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=23903&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23903&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=23903&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=23903&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=23903&r=gnused

Reply via email to