Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > note 74407 added to function.preg-replace
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 19th January 22:59
al~x2
External User
 
Posts: 1
Default note 74407 added to function.preg-replace


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
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666