Jump to content

how to include something inside an echo statement?


DataSpy

Recommended Posts

Hello, I'm trying to include something inside an echo statement, also echo back a variable and am having some trouble.

[code]<?php
$index = $_GET['index'];
if ($index==null)
{
    header("Location: ?index=home"); exit;
}
elseif ($index=="home")
{
    echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title>untitled</title>
</head>
<link rel="stylesheet" type="text/css" href="css.css">
<body bgcolor="B0C4DE" text="#000000" link="#000000" vlink="#000000" alink="#000000" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
echo "$var1";
echo "$var2";
include ("includes/footer.php");
;}
?>
[/code]

I know a way around it is to cut it off when the variable comes in and then do another elseif for the variables, but I was wondering if there was a better way.  Any help greatly appretiated, thanx in advance!
Use an output buffer.
From php.net:

[code]<?php
$string = get_include_contents('somefile.php');

function get_include_contents($filename) {
  if (is_file($filename)) {
      ob_start();
      include $filename;
      $contents = ob_get_contents();
      ob_end_clean();
      return $contents;
  }
  return false;
}

?> [/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.