note 85070 deleted from function.file-get-contents by nicos

From: Date: Thu, 14 Aug 2008 00:50:38 +0000
Subject: note 85070 deleted from function.file-get-contents by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143472@lists.php.net to get a copy of this message
Note Submitter: joomlatizer at gmail dot com Reason: 1 ---- /////////////////////////////////////////////////// // file_get_contents will attempt to parse javascript /////////////////////////////////////////////////// <? /* If you're trying to use file_get_contents to read, search and replace data inside the <script> and </script> tags from an html file , file_get_contents will try to parse it and show nothing. You'll need to use ob_get_contents to get the data inside the scripts tags as string then apply your search replace function. Example: */ ?> <?php //THIS DOESN'T WORK foreach($files as $file){ $HMTL=file_get_contents($file); $joomlatized=str_replace($search,$replace,$HTML); echo "<pre>".htmlspecialchars($joomlatized)."</pre>"; echo "<hr>"; } }//end_fns //THIS WILL WORK foreach($files as $file){ $HMTL=getFileContent($file); $joomlatized=str_replace($search,$replace,$HTML); echo "<pre>".htmlspecialchars($joomlatized)."</pre>"; echo "<hr>"; } }//end_fns //////////////////////// function getFileContent($path) {//////////////////////// ob_start(); include($path); $output=ob_get_contents(); ob_end_clean(); return $output; } //hope it saves you some frustration. ?>

« previous php.notes (#143472) next »