Jump to content

[SOLVED] Embed html code in php script


aashcool198

Recommended Posts

Now you're getting into template territory..... example (very basic and not best practice)

 

the html file (content.html)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
      <base href="{BASE_HREF}" />
      
      <!-- META DATA -->
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <meta name="title" content="{PAGE_TITLE}" />
         <meta name="keywords" content="{KEYWORDS}" />
      
      <!-- FAVICON -->
         <link rel="icon" href="favicon.ico" type="image/vnd.microsoft.icon" />
         <link rel="shortcut icon" href="favicon.ico" type="image/vnd.microsoft.icon" />
      
      <!-- STYLESHEETS -->
         <style type="text/css" media="screen">
            /* <![CDATA[ */
            @import url(static/css/default.css);
            /* ]]> */
         </style>
         <!--[if lte IE 7]>
            <link rel="stylesheet" type="text/css" href="static/css/IE/IE.css" />
         <![endif]-->
         <!--[if IE 6]>
            <link rel="stylesheet" type="text/css" href="static/css/IE/IE6.css" />
         <![endif]-->
      
      <!-- JAVASCRIPT FILES -->
         {JS}
      
      <title>{PAGE_TITLE}</title>
   </head>
   <body>
      <!-- I haven't done this bit, above is enough -->
   </body>
</html>

 

the php file (index.php)

 

<?php
$html = file_get_content("content.html");
$replaceThis = array('{BASE_HREF}', '{PAGE_TITLE}', '{KEYWORDS}', '{JS}');
$replaceWith = array('http://www.example.com/', 'A test page', 'keyword1, keyword2','<script type="text/javascript" src="a-javascript-file.js></script>"');
$html = str_replace($replaceThis, $replaceWith, $html);
echo $html;

 

I just wrote that quick, but you get the idea

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.