note 43265 added to function.preg-replace-callback
| From: | plyatukrpostdotnet at rn2 dot php dot net | Date: | Wed, 16 Jun 2004 07:11:46 +0000 |
| Subject: | note 43265 added to function.preg-replace-callback | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71127@lists.php.net to get a copy of this message | ||
Example given for preg_replace_callback with create_function have one flow - it consume a lot of
memory. Each call to create_function allocate some memory to create a new function, and to the end
of the script a lot of memory could be consumed, if there are many lines recieved from stdin. Of
course after ending all memory will be freed, but I have been hanged up my computer processing 20Mb
file with similar code on Windows.
<?php
$fp = fopen("php://stdin", "r") or die("can't read stdin");
while (!feof($fp)) {
$line = fgets($fp);
$line = preg_replace_callback('|<p>\s*\w|',
// this will create as many new functions, as there are lines recieved
create_function(
'$matches',
'return strtolower($matches[0]);'
),
//
$line
);
echo $line;
}
fclose($fp);
?>
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43265
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43265&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43265&report=yes
Search -- http://master.php.net/manage/user-notes.php