note 43265 deleted from function.preg-replace-callback by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:44:04 +0000 |
| Subject: | note 43265 deleted from function.preg-replace-callback by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127650@lists.php.net to get a copy of this message | ||
Note Submitter: ply at ukrpost dot net
----
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);
?>