note 83142 added to function.preg-replace

From: Date: Mon, 12 May 2008 21:39:45 +0000
Subject: note 83142 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-139315@lists.php.net to get a copy of this message
Here's a problem I'm having with preg_replace. I'm looking up a value associated with a string and replacing it with the associated id for better performance when pushed to production. When I deal with escapable or special characters, I run into the problem of being able to detect them (preg_match_all) but I can't replace them!!!!!!!! [exec] line: <span><?php echo __('Password') ?> <?php echo __('Wel\"come,') ?></span> [exec] replace: Array [exec] ( [exec] [0] => 2 [exec] [1] => 8 [exec] ) [exec] pattern: Array [exec] ( [exec] [0] => /Password/ [exec] [1] => /Wel\"come,/ [exec] ) [exec] finished line:: <span><?php echo __('2') ?> <?php echo __('Wel\"come,') ?></span> [exec] [exec] Replacing 2 keys in.................. Not sure why it's doing this. Here's the code. <?php private function replaceLine($linenum, $line) { //Local or make member variables???? $regs = NULL; $count = preg_match_all($this->_pattern, $line, $regs); $replacements = Array(); $patterns = Array(); if ($count) { foreach ($regs[1] as $val) { $replacements[] = array_search($val, $this->_xliff_data); $patterns[] = "/$val/"; } fwrite($this->_output_file, preg_replace($patterns, $replacements, $line)); echo "Replacing $count keys in $this->_filename -- Line:".($linenum+1)."\n"; } else { fwrite($this->_output_file, $line); } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 38.97.106.66 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/83142 Del: integrated -- https://master.php.net/note/delete/83142/integrated Del: useless -- https://master.php.net/note/delete/83142/useless Del: bad code -- https://master.php.net/note/delete/83142/bad+code Del: spam -- https://master.php.net/note/delete/83142/spam Del: non-english -- https://master.php.net/note/delete/83142/non-english Del: in docs -- https://master.php.net/note/delete/83142/in+docs Del: other reasons-- https://master.php.net/note/delete/83142 Reject -- https://master.php.net/note/reject/83142 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139315) next »