note 84724 added to function.preg-replace

From: Date: Sun, 27 Jul 2008 19:37:28 +0000
Subject: note 84724 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-142819@lists.php.net to get a copy of this message
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? ---- Server IP: 210.51.44.91 Probable Submitter: 58.207.176.16 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/84724 Del: integrated -- https://master.php.net/note/delete/84724/integrated Del: useless -- https://master.php.net/note/delete/84724/useless Del: bad code -- https://master.php.net/note/delete/84724/bad+code Del: spam -- https://master.php.net/note/delete/84724/spam Del: non-english -- https://master.php.net/note/delete/84724/non-english Del: in docs -- https://master.php.net/note/delete/84724/in+docs Del: other reasons-- https://master.php.net/note/delete/84724 Reject -- https://master.php.net/note/reject/84724 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142819) next »