file_get_contents() removing tab and new line characters
Posted
by
Patrick Murray
on Stack Overflow
See other posts from Stack Overflow
or by Patrick Murray
Published on 2012-12-10T22:34:41Z
Indexed on
2012/12/10
23:04 UTC
Read the original article
Hit count: 179
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;
?>
© Stack Overflow or respective owner