Jump to content

Wrong output to screen

- - - - -

  • Please log in to reply
4 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi. Could anyone tell me what makes this function always print "1" at the top of the screen?

public function buildHeader(){
            $output = '<title>' . $this->title . '</title>' . "\n" .
                    (include 'styleLinks.php') . "\n" .
                    '</head>' . "\n" .
                    '<body>' . "\n" .
                    '<div id="pageStyle">' . "\n" .
                    '<div style="width: 1024px; height: 160px;">' . "\n" .
                    '<img src="images/natoFlag.jpg" class="headerImage headerImageAlignment"/>' . "\n" .
                    '<img src="images/banner.jpg" class="headerImageAlignment" style="width: 740px; height: 140px; border-radius: 
                                                                                            15px; -moz-border-radius: 15px; -webkit-border-radius: 15px; 
                                                                                            -khtml-border-radius: 15px;"/>' . "\n" .
                    '<img src="images/napoleonFlag.jpg" class="headerImage headerImageAlignment"/>' . "\n" .
                    '</div>' . "\n";
            return $output;
        }


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You include statement likely returns a value of some sort, and evaluates to 1 somewhere in your code. Try to take this include statement out of your variable and treat it separately.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
It's hard to imagine how to do that. I need to use include to load the html code from another file

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
include was not meant to be used for that, if there is any non-text code (PHP) then it will be written before it is placed in output. It is like saying this:

$variable = (echo "foo" . "some other stuff");

It would simply echo foo regardless of you instructing it to be stored in $variable.

You would need to look at an option such as file_get_contents() of which parses the PHP and returns a plaintext which can be safely wrapped in a string.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
thanks alot, Alexander. file_get_contents() helped to solve that problem




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users