Jump to content

Archived

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

tomfmason

printing html

Recommended Posts

I have a main php file that has three columns with header and footer. The content is the only thing that will change from page to page. I am wondering how I can give the content a variable name and print it into the main. php

here is the main.php
[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>The Home of Owpt</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body bgcolor="#707070">
<div id="master">
<div id="masthead">
  <?php include("header.php"); ?>
</div>
<div id="navBar">
<?php include("navbar.php"); ?>
</div>
<!--end navBar div -->
<div id="headlines">
<?php include("headlines.php"); ?>
</div>
<!--end headlines -->
<div id="content">
<?php print('$content'); ?>       
</div>
<!--end content -->
<div id="siteInfo">
<?php include("footer.php"); ?>
</div>
</div>
<br>
</body>
</html>[/code]

and here is the content for the main page
[code]<?php
include("includes/main.php");
$content =
"<div class="feature">
    <img src="images/php.jpg" alt="" width="160" height="120">
    <p>
    <b>Look Ma No Tables</b>
    </p>
    <p>
    This is a test page that is made entirely of css layouts.
    </p>
    <p>
    I am knew to web design. I know that this is a very simple layout but
    it is my first.
    </p>
    <p>
    So Back Off....LOL
    </p>
  </div>
  <div class="story">
    <h3>Goals</h3>
    <p>
    My main goals are to learn html/xhtml, css, php. I will be posting tutorials
    based on my experience. One of the first tutorials that I will be creating is
    a step by step instruction on developing css based layouts. This means that I
    must learn more about it first...lol
    </p>
  </div>
  <div class="story">
    <h3>Problems</h3>
    <p>
    I have several problems the first being the layout of my columns.
    </p>
    <p>
    &lt;------------------------------------------------------------------------------------------------&gt;
    </p>
    <p>
    I would like the right, left and center columns lengths to be the same as
    the longest of the three. There are many more but I will try to figure them
    out my self.
    </p>
  </div>"
?> [/code]

I know that I can use echo but I don't think that that is the proper way to do it. Any suggestions would be great.

Share this post


Link to post
Share on other sites
It's perfectly fine to use echo, although you must be careful with your quotes, you must escape double quotes if your text is enclosed in double quotes, or replace them with single quotes.
[code]<?php
//This is correct
echo "Hello, my name is 'Kris', pleased to meet you.";

//This is also correct
echo "Hello, my name is \"Kris\", pleased to meet you.";

//This is incorrect
echo "Hello, my name is "Kris", pleased to meet you.";
?>[/code]
An alternative would be to use the HEREDOC syntax, you can see how to use it [url=http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc]here in the manual[/url].

Share this post


Link to post
Share on other sites
I fixed the syntax errors...ie the double quotes. I also included the main.php in the beging of the content page instead of at the end.

I made this a lot more complacated then it needed to be...lol


The fix to the content page:
[code]<?php 
$title = "The Home Of Owpt"; 
$content = "
  <div class=\"feature\">     
    <img src=\"images/php.jpg\" alt=\"\" width=\"160\" height=\"120\">
    <p>
    <b>Look Ma No Tables</b>
    </p>
    <p>
    This is a test page that is made entirely of css.
    </p>
    <p>
    I am knew to web design. I know that this is a very simple layout but
    it is my first.
    </p>
    <p>
    So Back Off....LOL
    </p>
  </div>
  <div class=\"story\">
    <h3>Goals</h3>
    <p>
    My main goals are to learn html/xhtml, css, php. I will be posting tutorials
    based on my experience. One of the first tutorials that I will be creating is
    a step by step instruction on developing css based layouts. This means that I
    must learn more about it first...lol
    </p>
  </div>
  <div class=\"story\">
    <h3>Problems</h3>
    <p>
    I have several problems the first being the layout of my columns.
    </p>
    <p>
    &lt;------------------------------------------------------------------------------------------------&gt;
    </p>
    <p>
    I would like the right, left and center columns lengths to be the same as
    the longest of the three. There are many more but I will try to figure them
    out my self.
    </p>
  </div>" 
?>
<?php include("includes/main.php"); ?>[/code]

Thanks for your help

Share this post


Link to post
Share on other sites

×

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.