Jump to content

[SOLVED] Question re ob_start()


Yesideez

Recommended Posts

Just playing with this. I thought when ob_start() was called nothing is sent to the browser?

 

Eg.

function doHomePage() {
  ob_start();
  include('homepage.php');
  $page=ob_get_contents();
  echo $page;
}

 

The contents of homepage.php is just HTML.

 

What I'm getting is the contents of homepage.php twice!

 

Am I doing something wrong or is this a configuration problem?

Link to comment
Share on other sites

When capturing output to the buffer does anything get "added" at the start?

 

When I use this I get an empty space at the top right before where homepage.php is being shown and I can't get rid of it even though my CSS is setting margin and padding all to 0.

 

In index.php I'm checking "page" which is being sent in the URL (eg. index.php?page=home) and this is the function that gets called:

function doHomePage() {
  echo '<h1>Hello</h1>';
  include('homepage.php');
  $page=new homepage();
  echo $page->contents();
  unset($page);
}

 

This is the contents of homepage.php:

<?php
class homepage {
  function contents() {
    ob_start();
?>
<h1>Welcome...</h1>
<p>Test line 1</p>
<p>Test line 2</p>
<?php
    $tmp=ob_get_contents();
    ob_end_clean();
    return $tmp;
  }
}
?>

Link to comment
Share on other sites

This is index.php in full...

<?php
  /* File: index.php
  ** Started: 08-Feb-2009 (Ivan Rood)
  ** Edited : 08-Feb-2009 (Ivan Rood)
  *********************************************************/
  require_once("includes/dbconfig.php");
  require('includes/site.php');
?>
<html>
<head>
  <title>Amiga Software Downloads :: Home</title>
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <link rel="shortcut icon" href="favicon.ico" />
<?php include("includes/metatags.php"); ?>
</head>
<body>
  <div id="wrapper">
    <div id="title">
       
    </div>
<?php require("includes/menu.php"); ?>
    <div id="wrap_left">
<?php
    switch (strtolower($_REQUEST['page'])) {
      case 'demos':doDemos();break;
      case 'games':doGames();break;
      case 'apps':doApplications();break;
      case 'lsd':doLSDDocs();break;
      case 'winuae':doWinUAE();break;
      case 'links':doLinks();break;
      case 'tome':doLinkToMe();break;
      case 'stats':doSiteStats();break;
      case 'contact':doContactMe();break;
      default:doHomePage();
    }
?>
    </div>
<?php
include("includes/panel_right.php");
include("includes/footer.php");
?>
  </div>
</body>
</html>

Link to comment
Share on other sites

This is what I've now changed in site.php:

function doHomePage() {
  echo '<h1>Hello</h1><h1>test</h1>';
  include('homepage.php');
  $page=new homepage();
  echo $page->contents();
  unset($page);
}

 

This is now the contents of homepage.php:

<?php
class homepage {
  function contents() {
    ob_start();
    echo '<h1>Welcome...</h1>
<p>After a major re-vamp (and some much appreciated persuasion) I\'m back with a new-look site.</p>
<p>Before I go on I must say that there will be no Kickstart ROM images, Kickstart boot disks or Workbench disks available for download as these are all still held under strict copyright by <a href="http://www.amigaforever.com/" class="url">Amiga Forever</a>. If you see any software here that shouldn\'t, please <a href="contactme.php" class="url">contact me</a> letting me know who you are and what the file(s) are. With so many games and applications available for the Amiga computer over the years it\'s very difficult to keep track of what can and cannot be freely distributed.</p>';
    $tmp=ob_get_contents();
    ob_end_clean();
    return $tmp;
  }
}
?>

 

The output can be seen here: http://www2.pictureinthesky.net/

 

Note the big gap above "Welcome..." which I can't find out why is there.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.