file_get_contents() removing tab and new line characters
- by Patrick Murray
I am having an issue today with the file_get_contents() function. When reading large files, the newline and tab characters are often removed. Here is a minified example of how I am using this.
I hope I am not the only one who has encountered this issue! :O
Thank you for your time!
<?php
$file_name = "template.html";
$data = array( 'title' => 'Hello, World!',
'content'=> 'Hey stackoverflow!');
$file_contents = file_get_contents($file_name);
foreach($data as $comment_name => $replacement_value){
$search = "<!-- ".strtoupper($comment_name)." -->";
$file_contents = str_replace($search, $replacement_value, $file_contents);
}
echo $file_contents;
?>