PHP Classes

File: demo2.php

Recommend this page to a friend!
  Classes of Nikola Posa   HeadSection   demo2.php   Download  
File: demo2.php
Role: Example script
Content type: text/plain
Description: Example script.
Class: HeadSection
Class for generating head section of an web page.
Author: By
Last change: New example added.
Date: 14 years ago
Size: 1,814 bytes
 

Contents

Class file image Download
<?php
include_once('HeadSection.php');

$headSectionParams = array(
   
'title' => 'My site',
   
'meta' => array('name'=>'keywords', 'content'=>'test, generate, head'),
   
'css' => array('style.css', 'style/common.css'),
   
'js' => array('functions.js', 'js/test.js')
);

//Passing array as first argument, that will set startingTags to false, as we don't want to render <head> tags in this example.
$headSection = new HeadSection(array('startingTags'=>false), $headSectionParams);

$headSection->addMeta(array('name'=>'robots', 'content'=>'noindex, nofollow'), HeadSection::SET); //Explicitly sets meta tag value, overwriting any previous value(s).
?>
<html>
   
<head>
    <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
       
    <link href = "default.css" rel = "stylesheet" type = "text/css" />
       
<?php echo $headSection->render(8); //Outputing head section and also passing $indent parametar to render() method. ?>

</head>

<body>
    <p>Hello world!</p>
</body>

</html>

<?php
/*
Page source will look something like this:

<html>
   
<head>
    <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
       
    <link href = "default.css" rel = "stylesheet" type = "text/css" />
       
        <title>My site</title>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <meta name= "robots" content = "noindex, nofollow" />

        <link href = "style.css" rel = "stylesheet" type = "text/css" />

        <link href = "style/common.css" rel = "stylesheet" type = "text/css" />

        <script type = "text/javascript" src = "functions.js"></script>
        <script type = "text/javascript" src = "js/test.js"></script>
       
</head>

<body>
    <p>Hello world!</p>
</body>

</html>

*/
?>