开发者

newline on source code?

I'm making a simple global get configuration.

try to make a index.php

function config( $string ){
    require 'configuration开发者_运维问答.php';
    return $config[$string];
}

echo config('hello');
echo config('hello');

and a configuration.php

$config['hello'] = TRUE;

and yes as we can see it outputs 1.

but when we see the source, it will give us something like

newline on source code?

sorry for the stupid question, but I just cant stop asking.

Thanks for looking in.


Are there any newlines before your <?PHP - Tag or after the ?> in your 'configuration.php' ? If so, remove them, because PHP outputs everything it sees directly to the browser, if it's not enclosed by PHP Tags.


You're requiring configuration.php inside the config function. Any blank lines in configuration.php before the <?php or after the ?> are being output to the page.

Consider moving the require line outside the config function.


See this answer: Mysterious line break is being appended to ajax loaded content

You probably have line breaks from a different OS, and your editor isn't capable of displaying them. Some editors can, some ignore them. So for instance, if I were to have edited the file on a Mac and left a blank line, then you open it in Windows, your text editor might not show you the blank line, and you might even have a hard time deleting it.

Try to copy/paste the code into something like Windows Notpad, then copy/paste it back out. Notepad ignores everything it doesn't recognize.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜