note 84724 rejected from function.preg-replace by danbrown

From: Date: Sun, 27 Jul 2008 19:39:17 +0000
Subject: note 84724 rejected from function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142820@lists.php.net to get a copy of this message
Note Submitter: zionwilson at gmail dot com ---- marcin, if change your $cp = "/(\d)\s(\d)\s(\d)/e"; //pattern into: $cp = "/([1-9][0-9]*)\s([1-9][0-9]*)\s([1-9][0-9]*)/" the output is: ('8')*('4')+('2') and then change $cr = "'\\3*\\2+\\1='.(('\\3')*('\\2')+('\\1'))"; into $cr = intval('\\3')*intval('\\2')+intval('\\1'); the output is: 0 and further if change $cr into $cr = ('\\3' == '${3}' ? '${3}' . ' equals to ' . '\\3' : '${3}' . 'not equals to' . '\\3') the output is: 8not equals to8 i guess it's because php do compare before parse the result from \\3(when use a 'general' match pattern like ([1-9][0-9]*) rather than 'modifier-like' match pattern like \d), hence inval() won't work 'cause for string '\\3' or '${3}' the result is always zero. so what is the work around if i need php to parse "\\1" before doing any operation like inval(), or comparison?

« previous php.notes (#142820) next »