note 104482 added to function.preg-replace

From: Date: Fri, 17 Jun 2011 09:11:02 +0000
Subject: note 104482 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-180637@lists.php.net to get a copy of this message
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. ---- Server IP: 89.31.146.176 Probable Submitter: 82.216.179.22 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/104482 Del: integrated -- https://master.php.net/note/delete/104482/integrated Del: useless -- https://master.php.net/note/delete/104482/useless Del: bad code -- https://master.php.net/note/delete/104482/bad+code Del: spam -- https://master.php.net/note/delete/104482/spam Del: non-english -- https://master.php.net/note/delete/104482/non-english Del: in docs -- https://master.php.net/note/delete/104482/in+docs Del: other reasons-- https://master.php.net/note/delete/104482 Reject -- https://master.php.net/note/reject/104482 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180637) next »