note 104482 deleted from function.preg-replace by crell
| From: | crell@php.net | Date: | Fri, 01 Jul 2022 19:45:34 +0000 |
| Subject: | note 104482 deleted from function.preg-replace by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218850@lists.php.net to get a copy of this message | ||
Note Submitter: anyvie at devlibre dot fr
----
A variable can handle a huge quantity of data but preg_replace can't.
Example :
<?php
$url = "ANY URL WITH LOTS OF DATA";
// We get all the data into $data
$data = file_get_contents($url);
// We just want to keep the content of <head>
$head = preg_replace("#(.*)<head>(.*?)</head>(.*)#is", '$2', $data);
?>
$head can have the desired content, or be empty, depends on the length of $data.
For this application, just add :
$data = substr($data, 0, 4096);
before using preg_replace, and it will work fine.