RSS

How to Add PHP code to HTML

Wed, Jul 16, 2008

PHP

Method1. Just put <?php your PHP code ?> with HTML

Method2. Use one of following functions:


<?php
    require('folder/file.php');
    require_once('folder/file.php');
    include('folder/file.php');
    include_once('folder/file.php');
?>


The difference between require,include and require_once,include_once is when you use include_once or require_once, the file will be included only once in a php system. For example: you have a file named hello.php witch only has a single line of code to echo a message to say hello.


<?php
    echo "hello.php";
?>

and you have a file named include.php witch is attempt to include the “hello.php” file.


<?php
    include('hello.php');
    include('hello.php');
    include('hello.php');    //You will get three times echo of "hello"
?>

if you have a file include_once.php, instead of include.php, to include the “hello.php” file.


<?php
    include_once('hello.php');
    include_once('hello.php');
    include_once('hello.php');    //You will get only one time echo of "hello"
?>

Related Posts

Tags: , , ,
Trackback URL:

This post was written by:

cXY - who has written 23 posts on cXY Lab.


Contact the author

Leave a Reply