php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38135 $n backreference not working in pattern
Submitted: 2006-07-18 17:56 UTC Modified: 2006-07-20 15:17 UTC
From: msn at t-network dot nl Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.1.4 OS: Windows XP SP2 Home Edition
Private report: No CVE-ID: None
 [2006-07-18 17:56 UTC] msn at t-network dot nl
Description:
------------
It's not possible to use the $n style backreference in the pattern of the PCRE functions.

A pattern like this:

/\[(u|b|i|s)\](.*)\[\/$1\]/si

Should match [b]bold[/b]. However, it does not.
This pattern though:

/\[(u|b|i|s)\](.*)\[\/\\1\]/si

_Will_ match [b]bold[/b].

Reproduce code:
---------------
<?php

function parseUBB($sString)
{
	
	// Bold, underline, italic and strike tags
	$sString = preg_replace("/\[(u|b|i|s)\](.*)\[\/$1\]/si", "<$1>$2</$1>", $sString);
	
	return ($sString);
}

echo parseUBB("[b]testb[/b], [u]testu[/u], [i]testi[/i]");

?>

Expected result:
----------------
<b>testb</b>, <u>testu</u>, <i>testi</i>

Actual result:
--------------
[b]test[/b], [u]testu[/u], [i]testi[/i]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-20 15:17 UTC] mike@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 15:01:31 2024 UTC