2

I have the following HTML template and I want to put it into a PHP file, the question I have is do I just wrap the template with <?php ?> or do I need to change around the JavaScript includes and the CSS style tag?

Here's the template

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <meta name="keywords" content=" some keywords for the bots">
    <meta name="author" content="my name here">
    <meta name="description" content="all about stuff here">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">  
        <title>site name</title>
        <link rel="shortcut icon" href="favicon.ico">
        <link href="style.css" rel="stylesheet" type="text/css" media="screen">
</head> 
<body onload="javascript_function()">
    <script language="JavaScript" src="js_include.js"></script>
</body>
</html>
2
  • 1
    just put it in the php file, the .php extension just tells the browser that there is php that needs to be watched for. regular html still applies. put your <?php ?> within the <html></html> tags where ever necessary Commented Feb 11, 2014 at 5:11
  • As there is no PHP code in your template just write this code in php file without php tags Commented Feb 11, 2014 at 5:11

7 Answers 7

4

Create any php file (test.php) like and place this whole code there.

there is no PHP code in your file, wherever you want to write php code in this new php file Start php tag and write code there.

<?php
//my php code here
?>

Ref PHP Basic

Sign up to request clarification or add additional context in comments.

Comments

3

You should save this file with .html or .php and use php include function() , <?php include("example.php"); ?> .

For more you want to know about file including , please check this link.

Comments

2

Just wrappping with a PHP tag is "sorta" right.

EG:

<?php
$foo="bar";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <meta name="keywords" content=" some keywords for the bots">
    <meta name="author" content="my name here">
    <meta name="description" content="all about stuff here">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">  
        <title>site name</title>
        <link rel="shortcut icon" href="favicon.ico">
        <link href="style.css" rel="stylesheet" type="text/css" media="screen">
</head> 
<body onload="javascript_function()">
    <script language="JavaScript" src="js_include.js"></script>
</body>
</html>


<?php
$foobar="something else";
?>

If you want to include your HTML inside the PHP code for some reason, you'll need to echo it as below.... or alternatively (better) save the HTML into a separate file and include(myHTMLfile.html); within the PHP

EG

<?php
  echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head><meta name="keywords" content=" some keywords for the bots"> ..... etc';
?>

Comments

2

You can write this code and in php fileand can access. No problem in that.

Comments

2

You can use this function to import any file in php

<?php require_once('path/filename.php'); ?> 

Comments

2
<link href="style.css" rel="stylesheet" type="text/css" media="screen">
<script language="JavaScript" src="js_include.js"></script>
<?php include( test.php); ?>

Comments

2

You just have to save your file and the include() function will include and evaluate it. If you don't have the <?php oppening tag in your template then there is nothing to evaluate, and in PHP everything outside <?php ?> will be writen to the default output.

Keep in mind that there is require(), include(), require_once(), include_once() too. In most cases require_once() is the good solution because it doesn't include already included files again.

Keep in mind that you need to give a correct path to your file too. The documentation on includes says in the beggining how it will search for the file.

With a handy expansion to also solve server path problems here is your final code:

<?php include($_SERVER['DOCUMENT_ROOT'].'/libary/yourtemplate.php'); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.