|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-10-18 09:56 UTC] fn at fkn-systems dot de
Description:
------------
In:
PHP 4.3.4 (cli) (built: Sep 24 2004 13:01:46)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
(also in PHP4.1.2 and PHP-CGI)
followed code (whitout newlines!)
$dat='2004-10-17/15:45.15';
echo'_'.preg_replace('/([.^\x5b]*?)(\x5b\x5b.*?\x5d\x5d)(.*)/s','\\1'."$dat".'\\3','# foo 1bar [changed: [[tic:tac]]] foo 2bar #').'_';
gives me
_# foo 1bar [changed: 004-10-17/15:45.15] foo 2bar #_
and not
_# foo 1bar [changed: 2004-10-17/15:45.15] foo 2bar #_
Reproduce code:
---------------
<?php
$dat='2004-10-17/15:45.15';
// (whitout newlines!)
echo'_'.preg_replace('/([.^\x5b]*?)(\x5b\x5b.*?\x5d\x5d)(.*)/s','\\1'."$dat".'\\3','# foo 1bar [changed: [[tic:tac]]] foo 2bar #').'_';
?>
Expected result:
----------------
_# foo 1bar [changed: 2004-10-17/15:45.15] foo 2bar #_
Actual result:
--------------
_# foo 1bar [changed: 004-10-17/15:45.15] foo 2bar #_
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 21:00:01 2025 UTC |
OBSOLETE: Was USER-ERROR: Sorry im very,very blind! :-( -- doku:preg_replace.html When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \\1 notation for your backreference. \\11, for example, would confuse preg_replace() since it does not know whether you want the \\1 backreference followed by a literal 1, or the \\11 backreference followed by nothing. In this case the solution is to use \${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal.