|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-27 23:43 UTC] felipe@php.net
[2008-07-28 01:06 UTC] zionwilson at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 05:00:01 2025 UTC |
Description: ------------ for the function preg_replace() i guess it does comparison and other operation before parse the result from '\\3', '\\2', '\\1' when use a 'general' match pattern like ([1-9][0-9]*) hence inval() won't work because for string '\\3' or '${3}' the result is always zero. however 'modifier-like' match pattern like \d, works well. so what is the fast work around if i need php to parse "\\1" before doing any operation like inval(), or comparison, at the moment? Reproduce code: --------------- <? $c1 = "2 4 8"; $cp1 = "/(\d)\s(\d)\s(\d)/e"; $cr1 = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))"; $c2 = "2 4 8"; $cp2 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/"; $cr2 = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))"; $c3 = "2 4 8"; $cp3 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/"; $cr3 = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))"; $c4 = "2 4 8"; $cp4 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/"; $cr4 = intval('\\3')*intval('\\2')+intval('\\1'); $c5 = "2 4 8"; $cp5 = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/"; $cr5 = ('\\3' == '${3}' ? '${3}' . ' equals to ' . '\\3' : '${3}' . 'not equals to' . '\\3'); echo (preg_replace($cp1,$cr1,$c1)); echo ("<br>"); echo (preg_replace($cp2,$cr2,$c2)); echo ("<br>"); echo (preg_replace($cp3,$cr3,$c3)); echo ("<br>"); echo (preg_replace($cp4,$cr4,$c4)); echo ("<br>"); echo (preg_replace($cp5,$cr5,$c5)); ?> Expected result: ---------------- 8*4+2=34 8*4+2=34 8*4+2=34 34 8equals to8 Actual result: -------------- 8*4+2=34 '8*4+2='.(('8')*('4')+('2')) '8*4+2='.(('8')*('4')+('2')) 0 8not equals to8