A bit of a strange one this, I’ve been re-coding some of my site to include switch functions that calls in various pieces of code (via an include command) depending on the country that they are visiting from.
The really wierd thing is that at the end of each switch function, PHP is printing out a number 1 into the middle of my website.
I can’t understand where this number is coming from as I’ve been through each of the individual scripts and there are definitely no number 1’s present at all.
Has anyone got any suggestions as to why this might be happening?
switch ($country) {
case GB:
include "content/news2/gb.php";
break;
default:
include "content/news2/default.php";
}
What happens is, first the include is executed, and then the echo displays the result of the include (which is 1: succesful).
Get rid of the echos and the 1 should disappear
Now, the ‘1’ is appearing after the last </div> of gb.php and before it comes back to the original index.php code, and there is just no ‘1’ in the code at all.
PHP is typecasting the boolean true (the result of the include statement). It true becomes an int of 1.
Include and require are pretty much like dropping in that code at the point you include it. So there’s no need to echo an include, rather if you need to echo you’d do that from within the file being included.