#29486 [Opn->Bgs]: / causes preg_replace troubles

From: Date: Sun, 01 Aug 2004 23:24:14 +0000
Subject: #29486 [Opn->Bgs]: / causes preg_replace troubles
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-63887@lists.php.net to get a copy of this message
ID: 29486 User updated by: slunta at msn dot com Reported By: slunta at msn dot com -Status: Open +Status: Bogus Bug Type: Output Control Operating System: Linux PHP Version: 4.3.8 New Comment: Sorry, I got it to work now. It was a modifyer issue >_>. Bug bogus. Previous Comments: ------------------------------------------------------------------------ [2004-08-02 01:21:43] slunta at msn dot com Please ignore the hyperlinks in the preg_replace code that was automatically created by this bug report page. Treat them as plain text. ------------------------------------------------------------------------ [2004-08-02 01:18:42] slunta at msn dot com Description: ------------ I don't know why, but a / right before a wildcard is causing a preg replace to stop. I don't believe it's a modifier issue either. Reproduce code: --------------- $message=isset($_POST['message']) ? htmlentities(trim($_POST['message'])) :''; $array1=array(); $array2=array(); $array1[]='/http:\/\/' . $_SERVER['HTTP_HOST'] . '\/(.*)/'; $array2[]='<a href="http://' . $_SERVER['HTTP_HOST'] . '/$1">http://' . $_SERVER['HTTP_HOST'] . '/$1</a>'; $output=preg_replace($array1,$array2,$message); Expected result: ---------------- In my case, the http host is turkeybot.olddh.com, and I post http://turkeybot.olddh.com/downloads/index.php. The output is expected to be: <a href="http://turkeybot.olddh.com/downloads/index.php">http://turkeybot.olddh.com/downloads/index.php</a> Actual result: -------------- The output I'm really getting is: <a href="http://turkeybot.olddh.com/">http://turkeybot.olddh.com/</a>downloads/index.php ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29486&edit=1

« previous php.bugs (#63887) next »