Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP adding empty text node before including html file

Tags:

php

I'm using php as templating engine, and I've noticed that when I include view file, empty text node is added before content of that view.

For example, I have html file I want to include that has following content:

<p>Some text</p>

than I include that file like this:

<div><?php require_once('file/path.htm'); ?></div>

(notice that I've removed any spaces between div and php) And after php includes file he adds empty text node (which I'll mark like this "") that adds space before p tag, so I get something like this:

Some previous content...
<div>    
"" //empty text node
<p>Some text</p>
</div>

This is quite problematic since it ruins content composition. Is there any solution to this?

like image 727
Jinx Avatar asked Jun 12 '26 00:06

Jinx


2 Answers

FSou1 has it right, it's the charset, it can also be solved by saving as UTF-8 without BOM:

  1. Open your PHP inlcude file in Notepad++ (download here: http://notepad-plus-plus.org/)
  2. Select Encoding --> Encode in UTF-8 without BOM

Empty nodes disappear. Hope that helps someone. This was driving me crazy.

like image 87
Killameters Avatar answered Jun 13 '26 16:06

Killameters


I had the same problem right now, and i had a luck when find answer. There answer is in charset. It could be strange, but when you save your file in UTF-8, you have empty in your markup. When your file in cp1251, you dont have this problem.