note 85070 added to function.file-get-contents
| From: | joomlatizer at gmail dot com | Date: | Wed, 13 Aug 2008 16:38:07 +0000 |
| Subject: | note 85070 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143451@lists.php.net to get a copy of this message | ||
///////////////////////////////////////////////////
// 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.
?>
----
Server IP: 209.41.74.194
Probable Submitter: 70.140.35.248
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit -- https://master.php.net/note/edit/85070
Del: integrated -- https://master.php.net/note/delete/85070/integrated
Del: useless -- https://master.php.net/note/delete/85070/useless
Del: bad code -- https://master.php.net/note/delete/85070/bad+code
Del: spam -- https://master.php.net/note/delete/85070/spam
Del: non-english -- https://master.php.net/note/delete/85070/non-english
Del: in docs -- https://master.php.net/note/delete/85070/in+docs
Del: other reasons-- https://master.php.net/note/delete/85070
Reject -- https://master.php.net/note/reject/85070
Search -- https://master.php.net/manage/user-notes.php