note 74407 deleted from function.preg-replace by colder

From: Date: Mon, 18 Jun 2007 20:09:51 +0000
Subject: note 74407 deleted from function.preg-replace by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127721@lists.php.net to get a copy of this message
Note Submitter: AL~X2 ---- At tomato at telenet dot be It isn't necessary to use preg_replace in that situation. It would be quicker and easier (on your CPU as well as yourself) to use str_replace. For example, in your code <?php if 'something is wrong' { $error = 'You killed cookie monster!. '; $html = preg_replace('/<body>/', '<body><p class="error">' . $error . '</p>', $html); unset($error); } ?> Could be replaced by <?php if 'something is wrong' { $error = 'You killed cookie monster!. '; $html = str_replace('<body>', '<body><p class="error">' . $error . '</p>', $html); unset($error); } ?> This saves about 3 bytes of HD space, a bit of memory, and the overhead incurred by using preg_replace

« previous php.notes (#127721) next »