Bug #78795 [Opn->Nab]: Preg_replace does not always replace
| From: | cmb@php.net | Date: | Fri, 08 Nov 2019 08:02:19 +0000 |
| Subject: | Bug #78795 [Opn->Nab]: Preg_replace does not always replace | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223644@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78795&edit=1
ID: 78795
Updated by: cmb@php.net
Reported by: markem at sim1 dot us
Summary: Preg_replace does not always replace
-Status: Open
+Status: Not a bug
Type: Bug
Package: Regexps related
Operating System: Windows 10
PHP Version: 7.3.11
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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.
For a start, see <https://3v4l.org/AsuaR>.
Previous Comments:
------------------------------------------------------------------------
[2019-11-08 03:01:12] markem at sim1 dot us
Description:
------------
---
From manual page: https://php.net/function.preg-replace
---
I was working on correcting a function by dawidgarus at gmail dot com. Got it working (yeah!). But
then decided to write my own and expand upon it. That was when I ran into this problem:
If you use preg_replace, the "replace" string can not use the $x or ${x} within another
variable (like an array). This generates an error.
Test script:
---------------
function bc()
{
$argv = func_get_args();
$cmd = $argv[0];
$cmd = preg_replace( "/\$(\d+)/", $argv[$1], $cmd );
return( $cmd );
}
$a = bc( "sqrt($1*$1+$2*$2)", 3, 5 );
Expected result:
----------------
$a should equal "sqrt(3*3+5*5)"
Actual result:
--------------
Notice: Undefined variable: i in C:\Users\Mark\My Programs\PHP\lib\bcd.php on line ###
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78795&edit=1