Jump to content


Photo

printing html


  • Please log in to reply
2 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 30 June 2006 - 09:58 AM

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
<!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>

and here is the content for the main page
<?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>"
?>

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.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 30 June 2006 - 12:14 PM

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.
<?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.";
?>
An alternative would be to use the HEREDOC syntax, you can see how to use it here in the manual.

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 30 June 2006 - 02:17 PM

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:
<?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"); ?>

Thanks for your help

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users