The switch function and the number 1

Hi there,

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?

Thanks very much

Oh I see, that makes sense.

I should have figured that out.

Thanks to everyone for the responses - I’ve learned something new today. Again :slight_smile:


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 :slight_smile:

This is what’s totally baffling me - the code is as follows, and as you can see there is no number 1 in the code at all.

index.php

				<?php
					switch ($country) {
    					case GB:
        					echo (include "content/news2/gb.php");
       						 break;
    					default:
      						echo (include "content/news2/default.php");
	 					 }
						 ?>
<div class="promo">
                  <div class="maintitle">Promo of the month</div>


gb.php


<div class="newsbox">
						<div class="newstitle">Title of news section</div>
						<p class="newscont">A load of news content goes here.
						</p>
						<div class="newsimg"><img src="http://www.mydomain.com/image.gif" alt="" /> </div>
				  <a href="http://www.playpokeronline.net/readmore" class="newsmore" target="_blank">readmore</a>					</div>
				</div>

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.

Try removing the echo before the include.

You can get an unexpected 1 in your output if you do print print "something";

So two times print. PHP first executes the second print, which returns true, upon which the first print prints 1

I know I’ve made this error more than once myself :sick:

It has to be something in your code that is doing it but without actually being able to see the code it is impossible to say what code it is.

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.