php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29486 / causes preg_replace troubles
Submitted: 2004-08-02 01:18 UTC Modified: 2004-08-02 01:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: slunta at msn dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.8 OS: Linux
Private report: No CVE-ID: None
 [2004-08-02 01:18 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-02 01:21 UTC] 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:24 UTC] slunta at msn dot com
Sorry, I got it to work now. It was a modifyer issue >_>. Bug bogus.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri May 27 19:05:46 2022 UTC