note 31389 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:01:32 +0000
Subject: note 31389 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55684@lists.php.net to get a copy of this message
Note Submitter: dave@britiany.com ---- I have found that preg_replace doesn't work well in the case of the PEAR Template class. This line in IT.php is doomed: $outer = (0 == count($regs)) ? $this->blocklist[$block] : preg_replace($regs, $values, $this->blocklist[$block]); The reason is that the $values array may contain entries with backslashes and or $ characters. My fix for this is: change: $regs[] = "@" . $this->openingDelimiter . $name . $this->closingDelimiter . "@"; to: $regs[] = $this->openingDelimiter . $name . $this->closingDelimiter; change: // $regs[] = "@".$this->openingDelimiter . $allowedvar . $this->closingDelimiter . "@"; to: $regs[] = $this->openingDelimiter . $allowedvar . $this->closingDelimiter; and change: $outer = (0 == count($regs)) ? $this->blocklist[$block] : preg_replace($regs, $values, $this->blocklist[$block]); to: if (0 == count($regs)) $outer = $this->blocklist[$block]; else { $outer = $this->blocklist[$block]; for ($dk=0; $dk<count($regs); $dk++) { $outer = str_replace($regs[$dk], $values[$dk], $outer); } } This way, I am using str_replace to replace the values instead of preg_replace. Conclusion: preg_replace should not be used when str_replace is what you are trying to do. Visit: http://dave.britiany.com:8081/ to discuss this further. This site is Help You Help Me PHP

« previous php.notes (#55684) next »