<!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>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<?php

include('header.php');

function displayLink($link_text,$link_url){
echo "<a href=\"$link_url\" title=\"Look at $link_text\">$link_text</a><br>";
}

function createMultipleLinks($folder,$url_prefix,$url_suffix,$num){
for($i=1;$i<=$num;$i++){
$i<10?$ii='0'.$i:$ii=$i;
$url=$folder.'/'.$url_prefix.$ii.'.'.$url_suffix;
$text=$url_prefix.' '.$i;
displayLink($text,$url);
}

}
echo '<h3>PHP Examples</h3>
<p>';
// an array to store our links in -
$link_array = array('trim','Loop example', 'Loop example with function','file write example','header','footer', 'this index page','folders','folders2','folders3','folders4','form','form_code','name','string','time','function','date');
// we use foreach to step through array
foreach ($link_array as $text){

// get url from title - will work if you stick to a convention
//first we replace spaces with underscores
// notice how we are continually overwriting the same variable, this is good practice
$url = str_replace(' ','_',$text);
//then we make string all lowercase
$url = strtolower($url);
// then we trim off any accidental whitespace
$url = trim($url);
// finally we add the folder and the file extention
$url = 'PHP_examples/'.$url.'.php';
/* the whole of the url from title routine could be domne on one line! See below, or it could be a function
$url = 'PHP_examples/'.trim(strtolower(str_replace(' ','_',$text))).'.php';
*/
// for every entry in the array we echo out the link and title via a function
displayLink($text,$url);
}
echo '</p>

<h3>HOE Examples</h3>
<p>These will be available at the end of the course only';
// an array to store our links in -
$link_array = array(4,6,'6a');
// we use foreach to step through array
foreach ($link_array as $ex_no){
$text = "Hands on exercise $ex_no example - this is not a model answer!";
//We add the folder, the prefix of the file and the file extention to create the link
$url = 'HOE_examples/hoe'.$ex_no.'.php';
// for every entry in the array we echo out the link and title via a function
//displayLink($text,$url);
}
/*
echo '</p>
<h3>Hands on exercise PDFs</h3><p>';
createMultipleLinks('HOE_pdfs','hoe','pdf',14);

echo '</p>
<h3>Lecture slides</h3><p>';
createMultipleLinks('Lecture_PDFs','slide','pdf',11);
*/
echo '</p>';

include('footer.php');
?>

</body>
</html>