note 74407 added to function.preg-replace
| From: | AL~X2 at osu1 dot php dot net | Date: | Tue, 10 Apr 2007 11:56:16 +0000 |
| Subject: | note 74407 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125260@lists.php.net to get a copy of this message | ||
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
----
Server IP: 194.145.210.4
Probable Submitter: 86.148.219.204
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/74407
Del: integrated -- https://master.php.net/note/delete/74407/integrated
Del: useless -- https://master.php.net/note/delete/74407/useless
Del: bad code -- https://master.php.net/note/delete/74407/bad+code
Del: spam -- https://master.php.net/note/delete/74407/spam
Del: non-english -- https://master.php.net/note/delete/74407/non-english
Del: in docs -- https://master.php.net/note/delete/74407/in+docs
Del: other reasons-- https://master.php.net/note/delete/74407
Reject -- https://master.php.net/note/reject/74407
Search -- https://master.php.net/manage/user-notes.php