Where is the 1 comming from?

  • tastysite
  • Proficient
  • Proficient
  • User avatar
  • Posts: 349
  • Loc: Brighouse, West Yorkshire, England

Post 3+ Months Ago

:fadein: HI I am using
Code: [ Select ]
include("inclueds/page.php")
in my site with a swich case but it the code it comes out with has a 1 in it here is the html code
Code: [ Select ]
<div id="content">
<!-- php changers page -->
<h1>home page</h1>hello there home page will have more things on it soon yay1</div>
<div id="footer"><center><small>tastysite web design - tastysite and tastysite logo &copy; 2008 - <a href="#bar">Back Up To Top Of Page</a></small></center></div>
  1. <div id="content">
  2. <!-- php changers page -->
  3. <h1>home page</h1>hello there home page will have more things on it soon yay1</div>
  4. <div id="footer"><center><small>tastysite web design - tastysite and tastysite logo &copy; 2008 - <a href="#bar">Back Up To Top Of Page</a></small></center></div>
only part of it.
this is what I have in my include
Quote:
<h1>home page</h1>hello there home page will have more things on it soon yay
no 1 so where is it coming from??
Note I have used this lots of times an always get the 1 in the code!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

what is the full php code? because you say you are using a switch but I don't see it ...
  • tastysite
  • Proficient
  • Proficient
  • User avatar
  • Posts: 349
  • Loc: Brighouse, West Yorkshire, England

Post 3+ Months Ago

That is because your looking the source code form the site this is the code I typed:
Code: [ Select ]
<?php

switch ($on) {
case "pricing":
    print "price";
    break;
case "contact":
    print "contact";
    break;
case "open":
    print "open";
    break;
default:
    print include("inclueds/home.php");
}

?>
  1. <?php
  2. switch ($on) {
  3. case "pricing":
  4.     print "price";
  5.     break;
  6. case "contact":
  7.     print "contact";
  8.     break;
  9. case "open":
  10.     print "open";
  11.     break;
  12. default:
  13.     print include("inclueds/home.php");
  14. }
  15. ?>
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Code: [ Select ]
<?php
switch ($on) {
case "pricing":
    print "price";
    break;
case "contact":
    print "contact";
    break;
case "open":
    print "open";
    break;
default:
    include("inclueds/home.php");
}
?>
  1. <?php
  2. switch ($on) {
  3. case "pricing":
  4.     print "price";
  5.     break;
  6. case "contact":
  7.     print "contact";
  8.     break;
  9. case "open":
  10.     print "open";
  11.     break;
  12. default:
  13.     include("inclueds/home.php");
  14. }
  15. ?>

That should work ...
  • Truce
  • Guru
  • Guru
  • Truce
  • Posts: 1477
  • Loc: Washington DC

Post 3+ Months Ago

tastysite wrote:
That is because your looking the source code form the site this is the code I typed:
Code: [ Select ]
 
<?php
 
switch ($on) {
case "pricing":
    print "price";
    break;
case "contact":
    print "contact";
    break;
case "open":
    print "open";
    break;
default:
    print include("inclueds/home.php");
}
 
?>
  1.  
  2. <?php
  3.  
  4. switch ($on) {
  5. case "pricing":
  6.     print "price";
  7.     break;
  8. case "contact":
  9.     print "contact";
  10.     break;
  11. case "open":
  12.     print "open";
  13.     break;
  14. default:
  15.     print include("inclueds/home.php");
  16. }
  17.  
  18. ?>


You problem is coming from the fact that you're echoing the result of the include statement. If successful, it's going to be 1. If you want to pass a value to print you need to modify your home.php and add a "return" to it passing the value that you want to have output.
  • tastysite
  • Proficient
  • Proficient
  • User avatar
  • Posts: 349
  • Loc: Brighouse, West Yorkshire, England

Post 3+ Months Ago

How would one do that?
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8399
  • Loc: USA

Post 3+ Months Ago

Code: [ Select ]
<?php
 
switch ($on) {
case "pricing":
    print "price";
    break;
case "contact":
    print "contact";
    break;
case "open":
    print "open";
    break;
default:
    print include("inclueds/home.php");
}
 
?>
  1. <?php
  2.  
  3. switch ($on) {
  4. case "pricing":
  5.     print "price";
  6.     break;
  7. case "contact":
  8.     print "contact";
  9.     break;
  10. case "open":
  11.     print "open";
  12.     break;
  13. default:
  14.     print include("inclueds/home.php");
  15. }
  16.  
  17. ?>

The bold thing is what he is talking about. To show you (visually) what he is talking about:
Code: [ Select ]
<?php
if(include("inclueds/home.php"))
{
  return '1';
} else {
  return '0';
}
?>
  1. <?php
  2. if(include("inclueds/home.php"))
  3. {
  4.   return '1';
  5. } else {
  6.   return '0';
  7. }
  8. ?>

That is what you are doing with:
Code: [ Select ]
<?php
print include("inclueds/home.php");
?>
  1. <?php
  2. print include("inclueds/home.php");
  3. ?>

If you want to include the contents of "inclueds/home.php" then drop the print, or put a value that home.php should return... like...

inclueds/home.php
Code: [ Select ]
 
<?php
   /** Some code here or whatever **/
   return "HTML or regular text here";
?>
  1.  
  2. <?php
  3.    /** Some code here or whatever **/
  4.    return "HTML or regular text here";
  5. ?>

And then you could use that print in the switch operator.

By the way, it's includes... not inclueds :)
  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 565
  • Loc: Fort Worth, TX

Post 3+ Months Ago

Yeah, just get rid of the "print" keyword, as you are including.. not echoing.. you can only print/echo strings..

when you "print include" something (a statement) it prints 1 (or 0), because it thinks it is a Boolean (true/false) statement. So if the file is included successfully it will print 1, otherwise it will print 0 (or nothing, since an empty string is also considered false), (1=true,0=false), when you include it, it will print the output of the included file for you, so you do not have to echo it, again.

Code: [ Select ]
$result = include("includes/home.php");
 
if($result) {
 //include success
} else {
//include failed
}
//in your case.. you are trying to echo $result..
 
//will print 1
print $result
 
  1. $result = include("includes/home.php");
  2.  
  3. if($result) {
  4.  //include success
  5. } else {
  6. //include failed
  7. }
  8. //in your case.. you are trying to echo $result..
  9.  
  10. //will print 1
  11. print $result
  12.  



Above statement is where your script is going..

Your can also represent your current statement as
Code: [ Select ]
print TRUE;


Code: [ Select ]
..also noticed you have typo in your statement....
include("inclueds/home.php");
Bogey pointed that out as well
  1. ..also noticed you have typo in your statement....
  2. include("inclueds/home.php");
  3. Bogey pointed that out as well


I also agree with Truce

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: VanessaGilbert and 123 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.