I'm having a very weird problem with the file_get_contents() function. It has worked well for me before, but it has started screwing up lately, and I have no clue why. Basically, I have a bunch of template files (.tpl files), and I use the function file_get_contents() to get their contents, then I convert them into PHP code that is then eval()'d. Now, the problem is that the HTML has random line breaks that I did not add. This screws up the template engine, because it echo's an empty line each time, slowing the system down and messing up the code.
Today I tried commenting the actual template engine out to see if there was a problem with the load_template() function that I wrote. Well...after doing a few tests, I figured out that it added those line breaks (and took off a few) in the file_get_contents() function. In my template.tpl file, I do not have more than 1 line break in a row. I did this test:
<?php
$tpl = file_get_contents('templates/template.tpl');
echo $tpl;
?>
And what I got was 4 (I think) line breaks in a row, somewhere in the <head> tag of the HTML. This is strange because it happens whenever I use that function (file_get_contents) on ANY file that has HTML.
If needed, here is the original HTML compared to the output:
Original:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>SwiftBlog</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="content-language" content="en-us" />
<link rel="stylesheet" href="templates/style.css" type="text/css" />
<script type="text/javascript" src="js/basic.js"></script>
<script type="text/javascript" src="js/style.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" src="js/init.js"></script>
</head>
<body>
<div class="page">
<div class="leftmenu">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php">Test</a></li>
<li><a href="index.php">Test</a></li>
</ul>
</div>
<div id="content">
Test
</div>
</div>
<div class="copywrite">
This blog is proudly powered by <a href="http://www.swiftblog.net">SwiftBlog</a>
</div>
</body>
</html>
Output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>SwiftBlog Test</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="content-language" content="en-us">
<link rel="stylesheet" href="templates/style.css" type="text/css"></head><body>
<div class="page">
<div class="leftmenu">
<ul>
<li><a href="index.php">Home</a></li>
</ul>
</div>
<div id="content">
Test
</div>
</div>
<div class="copyright">
This blog is proudly powered by <a href="http://www.swiftblog.net">SwiftBlog</a>
</div>
</body></html>
Thanks in advance!
PS: Two things....
1. Don't tell me to use Smarty. 😛
2. Please don't comment on how bad my HTML is (unless it solves my problem)...this is just for a test...