开发者

Extra whitespace, on HTML output, on PHP MVC

I'm getting extra whitespace, that is not CSS, or nothing like it on the view output: The HTML.

I've checked for ?> (removed, where I could), saved UTF8 without BOM. Checked for existent white space in the beginning of each file, even at end.

This is the structure:

index.php - this is the entry point;
MODEL/
CONTROLLER/
VIEW/

Let's say, that trough method GET, its sent the var TPL with some value. Let's call it LIST, so it pulls the LIST model, with all data and then show the right template to the user, with the right data.

I used and tested, with require_once, include_once, include, even tested with readfile (just to test). The LIST Template opens the header.tpl and footer.tpl; I also tryed to remove this both includes from LIST template, but still, the extra white space continued.

This is where the extra white space is coming from. This controller is placed between <body> controller activity runs here </body>, this is where the extra white space is coming from:

$model_works->getRows();

$rows = $model_works->rows;

if ( !require_once('views/list_works.tpl.php') ) {

echo "<p>Error.</p>";

} // end if clause

The list_works.tpl.php, is basicly HTML with tags; I've t tested by changing the extension to something else, like html.

Also, just to remember that at top of this file, we are using require_once to open the header.tpl and at bottom the footer.tpl. I've tested by removing both and the extra white space was still generated.

The extra white space is being generated here:

<body>
# EXTRA WHITE SPACE HERE #
<!-- some stuff w开发者_C百科orking fine -->
</body>  

Thanks a lot for looking, ;D


Try to open your file in a low level text editor like MS-Dos Edit , You may find some control bytes remove it and it will be fine.


I had the same problem, when using require got a blank space at the beginning of the body, before the rest of the document. My solution has been quite simple:

<!--Dummy HTML comment<? require something.php ?>-->

This way the blank space is in the comment and it's not shown. The problem is that any return from the required file is also inside the comment, so you might put this return in a function in the required file, and call it from the native file to finally get the data and put it wherever you want. My apache server has no problem reading PHP code inside a HTML comment, but I'm not sure this will work in any other place.


An additional line-break in one of your files, a stray echo, keep commenting stuff out till you find it ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜