|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-04-10 16:50 UTC] blueroom at digitalmente dot net
Actually, this is quite simple.
Take this:
$preg_replace("/.\:\\.*?\\(.*?).gif/i","http://xpto/\\1.img",$string);
Theoretically, this would make a simple find-replace, but PHP throws out a "unmatched parenthesis" error (Compilation failed: unmatched parentheses at offset 12 blablabla...). With the only parentheses in that regexp being the "(.*?)" in the middle, the error is awkward.
After some juggling I eventually found that it seems that in the "\\(.*?)" part of the expression, the backslash before the parenthesis gets replaced with an actual parenthesis BEFORE the double-backslash is replaced with an actual backslash. I tried putting a space before the parenthesis and no error appeared (obviously, the regexp didn't work like that :).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
'\' and '\\' will both end up as a single '\' in the string which effectively reads \( to the preg parser which means you escape the '(' and so don't use it's function to capture characters for backreferences which renders the following ')' illegal since it tries to close a not opened '('. Therefore, \ -> \ and \\ -> \ so you need \\\ to get \\ in the string so you don't escape the (. Clear ? :) Providing input data for such reports is essential.