Question embedding html in a php code.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Blayke
Forum Newbie
Posts: 2
Joined: Mon Jan 04, 2010 10:28 pm

Question embedding html in a php code.

Post by Blayke »

I am trying to use a templating system to get my site to work, and I am having trouble replacing tags with html.
I need index.php to show the content from the content table when the user requests index.php?do=test in the slot on template.html when the script calls {body}. Sorry if this is too complicated, or un-organized but help would be greatly appreciated.

Index.php

Code: Select all

 
<?php
    require_once("lib/template.php");
    require_once("style.css");
 
    $page = new Page("template.html");
 
    if ($_REQUEST['do'] == 'test')
    {
    require_once("lib/test.php");
    $page->replace_tags(array(
        "title" => $title,
        "descript" => "*****.com",
        "body" => **Show the content from CONTENT TABLE**,
        "menu" => "dat/menu.dat",
        "left" => "dat/submenu.dat",
        "right" => "dat/right.dat",
        "footer" => $footer,
    ));
        }
 
    $page->output();
?>
lib/test.php

Code: Select all

 
<?php
 
 
    $title = "This is the **** test page";
    $footer = "this is the footer";
 
         
?>
Template.html

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{title}</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<center>
<table width="900" height="587" border="0" borderwidth="0">
  <tr>
    <th height="78" class="header" scope="row"><div align="left">
      <table width="900" border="0">
        <tr>
          <th width="711" scope="col"><img src="*************" alt="****" width="102" height="54" align="left" longdesc="********" /></th>
          <th width="179" scope="col">Login Area</th>
        </tr>
      </table>
    </div></th>
  </tr>
  <tr>
    <th height="29" scope="row" class="tools"><div align="left">What's ****? | Sign Up! </div></th>
  </tr>
  <tr>
    <th  height="408" class="header" scope="row">[b]{body}[/b]</th>
  </tr>
  <tr>
    <th height="62" class="header" scope="row">[b]{footer}[/b]</th>
  </tr>
</table>
</center>
</body>
</html>
 

CONTENT TABLE

Code: Select all

<table align="right"width="850" border="">
        <tr>
          <th width="283" scope="col"><img align="left" src="Images/micro_pic_board.png" width="247" height="162" alt="SnowBoard" /></th>
          <th width="283" scope="col"><img align="left" src="Images/micro_pic_club.png" width="247" height="162" alt="Club" /></th>
          <th width="283" scope="col"><img align="left" src="Images/micro_pic_family.png" width="247" height="162" alt="Family Dinner" /></th>
        </tr>
        <tr>
          <th scope="row">&nbsp;</th>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th height="81" scope="row">&nbsp;</th>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
Last edited by Blayke on Tue Jan 12, 2010 9:18 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Question embedding html in a php code.

Post by Christopher »

Use the str_replace() function to replace the {tags} with the values.
(#10850)
Blayke
Forum Newbie
Posts: 2
Joined: Mon Jan 04, 2010 10:28 pm

Re: Question embedding html in a php code.

Post by Blayke »

Sorry if this sounds like a dumb question but where do I put the str_replace?

I have my test.php looking like this now:

Code: Select all

<?php
 
 
    $title = "This is the******  test page";
    $footer = "this is the footer";
    
    $rawstring = "Content";
    
    $body = str_replace("Content","<table align="right"width="850" border="">
        <tr>
          <th width="283" scope="col"><img align="left" src="Images/micro_pic_board.png" width="247" height="162" alt="SnowBoard" /></th>
          <th width="283" scope="col"><img align="left" src="Images/micro_pic_club.png" width="247" height="162" alt="Club" /></th>
          <th width="283" scope="col"><img align="left" src="Images/micro_pic_family.png" width="247" height="162" alt="Family Dinner" /></th>
        </tr>
        <tr>
          <th scope="row">&nbsp;</th>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th scope="row">&nbsp;</th>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>",$rawstring);
    
    
 
      
 
         
?>
     
 

EDIT: I was trying to use include("test.html"), would you think this may be a better way to handle this?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Question embedding html in a php code.

Post by Christopher »

Load the template file into a variable, use str_replace(), echo the variable.
(#10850)
Post Reply