<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Undergraduate</title>
	<atom:link href="http://www.the-undergraduate.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.the-undergraduate.co.uk</link>
	<description>Tutorials and Collaborations for our future programmers</description>
	<lastBuildDate>Wed, 24 Feb 2010 01:21:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Iterations in PHP</title>
		<link>http://www.the-undergraduate.co.uk/scripting/php/iterations-in-php/</link>
		<comments>http://www.the-undergraduate.co.uk/scripting/php/iterations-in-php/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 01:21:42 +0000</pubDate>
		<dc:creator>Steffy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=253</guid>
		<description><![CDATA[Hello, campers! Now then, let&#8217;s get stuck in. You can easily write a huuuuuuge article explaining iterations and how they...]]></description>
			<content:encoded><![CDATA[<p>Hello, campers! Now then, let&#8217;s get stuck in. You can easily write a huuuuuuge article explaining iterations and how they differentiate, how to use them, etc, etc, etc. Same goes for objects and classes too. However articles like that are long winded, boring and mindless drivel but I&#8217;ll try to keep this as to the point as it gets with references to other sources where you can further your reading if that suits you&#8230;</p>
<h1>Iterations</h1>
<p>Some statements in programming and scripting languages are described as being<em> iterative </em>statements. These statements are structured and have conditions and terminating factors to control how many times the code in that block is executed. PHP has four major and commonly used iterative structures that we&#8217;ll look at now. These are:</p>
<ul>
<li><em>&#8216;while&#8217;</em></li>
<li><em>&#8216;do &#8230; while&#8217;</em></li>
<li><em>&#8216;for&#8217; </em></li>
</ul>
<p><span id="more-253"></span></p>
<h2>While</h2>
<p>The while statement is probably the most basic one of the lot. It simply executes a block of code continuously looping until it&#8217;s condition is no longer met. However if the condition is never met, the code is never executed.</p>
<pre class="brush:php">&lt;?php
while (expression) {
  statements;
  }
?&gt;</pre>
<p>or&#8230;</p>
<pre class="brush:php">&lt;?php
$x = 0;
while ($x &lt; 10) {
  echo 'Variable x holds the value: ' . $x;  // Note the use of the dot character to concatenate the string.
  $x++;
  }
?&gt;</pre>
<h2>Do&#8230;while</h2>
<p>With a traditional while statement the code will execute for the duration of time that it&#8217;s conditional statement is made true. With a do&#8230;while loop however the code will execute once regardless of the conditional and only loop again if it&#8217;s conditional statement is met. Always a useful tool if you want something to happen at least once&#8230;</p>
<pre class="brush:php">&lt;?php
do {
  statements;
  }
while (expression);
?&gt;</pre>
<p>or&#8230;</p>
<pre class="brush:php">&lt;?php
$x = 0;
do {
  echo 'Variable x holds the value: ' . $x;  // Note the use of the dot character to concatenate the string.
  $x++;
} while ($x &lt; 10) ;
?&gt;</pre>
<h2>For</h2>
<p>The for loop lets programmers perform a loop based on an incremental value until it reaches it&#8217;s terminating value. Unlike the while loop the variable changes as part of the condition meaning less code in the body of the loop as we no longer need to adjust this variable in the loop to help it reach it&#8217;s terminating condition.</p>
<pre class="brush:php">&lt;?php
for (initialisation; condition; increment) {
  statements;
 }?&gt;</pre>
<pre class="brush:php"></pre>
<h2>Summary</h2>
<p>So that&#8217;s about it really! You should now understand the basics of PHP iterations and loops. All be what this post is about is pretty basic it is important to understand. My next post will be on if/else loops and case/switch statements as these have some special rules that would be a bit much to include in this post I believe. Go forth, young padawans&#8230;and iterate :)</p>
<p>or&#8230;</p>
<pre class="brush:php">&lt;?php
for ($x = 0; $x &lt; 10; $x++;) {   $a = $a + $b[$x];   $x++;   } &gt;&lt;</pre>
<p>So that&#8217;s</p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/scripting/php/iterations-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Malloc</title>
		<link>http://www.the-undergraduate.co.uk/programming/c/malloc/</link>
		<comments>http://www.the-undergraduate.co.uk/programming/c/malloc/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 16:51:46 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[dynamic array]]></category>
		<category><![CDATA[malloc]]></category>
		<category><![CDATA[memory allocation]]></category>
		<category><![CDATA[pointers]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=298</guid>
		<description><![CDATA[Malloc (or &#8216;memory allocation&#8217;) is an exceptionally useful tool in C that allows the programmer to create dynamically behaving arrays...]]></description>
			<content:encoded><![CDATA[<p>Malloc (or &#8216;<b>m</b>emory <b>alloc</b>ation&#8217;) is an exceptionally useful tool in C that allows the programmer to create dynamically behaving arrays and structures within their program. So, how does it work?</p>
<p>If you imagine that when a program is made, it uses up &#8216;blocks&#8217; of standard memory simply for it to run (while this is often minute, it&#8217;s still important to take into account). Memory is used upon compilation based on the number of instantiated variables within the code (ints, chars etc). This use of memory can be visualised as a grid with each block of memory available/used as squares within this grid. What malloc does is tell the program to &#8216;set aside&#8217; a given number of blocks of memory for later or current use.<br />
<span id="more-298"></span><br />
<h2>Using malloc</h2>
<p>When using malloc, there are two things to take into account. These are:</p>
<ol>
<li><b>Casting malloc to the variable type you wish to make dynamic.</b></li>
<p>When calling malloc on a variable, you want to tell it what kind of variable it is. This is done by &#8216;casting&#8217; malloc.</p>
<li><b>The <i>size</i> of each block of memory you are setting aside.</b></li>
<p>Different variables hold different sizes of memory. For example, an int has a size of four bytes. Telling malloc how large each block of memory needs to be is very important. If you do not do this, you will have problems trying to get the code to work in the way you wanted.
</ol>
<p>When using malloc, C is very intelligent when it comes to creating the dynamic arrays. Due to the nature of C89 programming, you <i>must</i> define a size for each array you instantiate within your code. This means that a dynamic array is structured a little differently. This is where pointers come in.</p>
<h2>Pointers</h2>
<p>A pointer is not a variable that holds a specific value. Instead, it <i>points</i> to a location in memory being held by the <i>type</i> of variable that it is. For example:</p>
<pre class="brush:c">
int *my_pointer;
</pre>
<p>This doesn&#8217;t allow storage of a value of type &#8216;int&#8217;. Instead, it &#8216;points&#8217; to the location in memory for an int. </p>
<p>Why use pointers then? Simple; malloc assigns blocks of memory to a variable, but as this variable is going to be of unknown size at the time of compilation, you want the pointer to at least know where the memory is. </p>
<h2>Two simple steps to making your own dynamic array</h2>
<ol>
<li>Instantiate two variables; One of type int (which will be a storage for the number of elements you want in your array), and the other being a <i>pointer</i> of the type of variable you wish to store within your array.</li>
<pre class="brush:c">
int bits_of_memory, *my_array;
</pre>
<li>When you have decided on how many elements your array will have, you need to malloc the pointer to point to that number of blocks of memory. <b>Don&#8217;t forget to CAST the malloc!</b>
<pre class="brush:c">
my_array = (int*)malloc(bits_of_memory * sizeof(int));
</pre>
</li>
</ol>
<p><b>What is going on here?</b> When you are assigning malloc to your array pointer, note that you have to cast it to the type of variable that it is. In this case, it&#8217;s a pointer to an int (i.e. &#8216;int*&#8217;). The number of blocks of memory is then reliant on the value of &#8216;bits_of_memory&#8217;. This is then multiplied by the total size of a single integer (four bytes).</p>
<p>If you imagine that the variable &#8216;bits_of_memory&#8217; had a value of 4, malloc will set aside &#8220;4 &#8216;times&#8217; the size of the variable&#8221; blocks of memory for you:</p>
<pre>
[int][int][int][int][  ][  ][  ]
</pre>
<p>And it&#8217;s that simple! Yes, it really is. As long as you remember the type of variables you&#8217;re playing around with, malloc will allow you to dynamically set aside blocks of memory.</p>
<h2>Handling the array</h2>
<p>As mentioned before, C is very intelligent when handling dynamic arrays. The moment you use malloc on a pointer, it automatically assumes you want to turn it into an array. This means that you can now use the variable like an array.</p>
<pre>my_array[0] is completely legal.</pre>
<p>In the example program below, I have placed the reading into and printing of the variable into a <a href="http://www.the-undergraduate.co.uk/programming/iteration-statements/">for loop</a>. This makes handling the array on a complete scale a lot easier, especially if you want to place all of the information in in one go.</p>
<h2>Example program:</h2>
<pre class="brush:c">
/*
 * File:   main.c
 * Author: Josh Greatrex
 *
 * Created on 08 February 2010, 16:08
 *
 * This file should give you a basic working knowledge of how malloc works
 * and how it can be used in C programming. Please feel free to copy this
 * source code and compile it yourself.
 */

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;malloc.h&gt;

int main() {

    int bits_of_memory, *my_array, i;

    printf("How big do you want this array to be? ");
    scanf("%d", &#038;bits_of_memory);

    /* Allocates memory for the array */
    my_array = (int*)malloc(bits_of_memory * sizeof(int));

    /* Allows the user to enter the values into the array */
    for(i = 0; i < bits_of_memory; i++) {
        printf("Enter the value for element %d: ", (i+1));
        scanf("%d", &#038;my_array[i]);
    }

    /* Prints off all of the element values from the array */
    for(i = 0; i < bits_of_memory; i++) {
        printf("Value for element %d is %d\n", (i+1), my_array[i]);
    }

    return 0;
}
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/programming/c/malloc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linked Lists</title>
		<link>http://www.the-undergraduate.co.uk/programming/c/linked-lists/</link>
		<comments>http://www.the-undergraduate.co.uk/programming/c/linked-lists/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 15:28:28 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[malloc]]></category>
		<category><![CDATA[pointers]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=270</guid>
		<description><![CDATA[A Linked List is a data structure that arranges data from a given input into a stored &#8216;list&#8217;. Each item...]]></description>
			<content:encoded><![CDATA[<p>A Linked List is a data structure that arranges data from a given input into a stored &#8216;list&#8217;. Each item in the list is known as a &#8216;node&#8217;.</p>
<p><a href="http://www.the-undergraduate.co.uk/wp-content/uploads/LinkedList.jpg"><img class="aligncenter size-full wp-image-294" title="LinkedList" src="http://www.the-undergraduate.co.uk/wp-content/uploads/LinkedList.jpg" alt="Simple diagram displaying a Linked List" width="400" height="91" /></a></p>
<p>Each node within the list contains the set data as well as a &#8216;pointer&#8217; to the next node within the list; hence &#8216;Linked List&#8217;.</p>
<p>Linked Lists in C utilise three things:</p>
<ol>
<li>malloc</li>
<li>structs</li>
<li>Pointers</li>
</ol>
<h2>Creating the structure</h2>
<p>A C struct acts as a &#8216;node&#8217; within the Linked List. One of the better ways to declare a C struct is to &#8216;typedef&#8217; it as such:</p>
<pre class="brush:c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

typedef struct my_struct_name {
    /* Declare the variables you want in each node */
    int i, j;
    char c;
    double d;

    /* Pointer for next node in list */
    struct my_struct_name *next_node;
} my_struct;</pre>
<p><strong>Note:</strong> The struct has, in essence, two names. Why? Well, the first name &#8216;my_struct_name&#8217; refers to that &#8216;type&#8217; of struct. The second name &#8216;my_struct&#8217; refers to that specific struct. Also note that there is a pointer within the struct, of that type, which will be used to point to the next node within the list.</p>
<p><span id="more-270"></span>And that&#8217;s the simplest way to create a node. So, what&#8217;s next?</p>
<p>When inserting and retrieving information from the linked list, you will not be calling the struct directly. You in fact need to create three more pointers, external to the struct. These are:</p>
<pre class="brush:c">my_struct *first_node, *current_node, *last_node</pre>
<p>These pointers will be what you refer to when dealing with your list.</p>
<h2>Malloc and Struct syntax</h2>
<p>Let&#8217;s miss out the part regarding file reading for now (that will be covered in another article) and assume you know what values you want within the list. How are you going to insert them? Quite simple:</p>
<ol>
<li>Begin a loop</li>
<li>Malloc the current node in order to reserve memory for that node:</li>
<pre class="brush:c">current_node = (my_struct*)malloc(sizeof(my_struct));</pre>
<li>If the head of the list has not been made, assign the current node to be the head of the list (or &#8216;first_node&#8217;). If the head already exists, assign the current_node to be the last_node&#8217;s &#8216;next_node&#8217; pointer:</li>
<pre class="brush:c">if(first_node == NULL)
    first_node = current_node;

else
    current_node = last_node -&gt; next_node;</pre>
<li>Insert your values by representing the variables within the current node in the structure:</li>
<pre class="brush:c">/*Remember this is a pointer and represents the structure*/
&amp;current_node -&gt; i = 42;
&amp;current_node -&gt; j = 100;
current_node -&gt; c = 'a';
&amp;current_node -&gt; d = 13.37;</pre>
<p>When you insert into the node, you use the &#8216;current_node&#8217; pointer ALWAYS. When you call &#8216;current_node&#8217;, you&#8217;re calling the structure it represents at a specific block of memory (previously reserved by malloc). The &#8216;-&gt;&#8217; means that you wish to insert or retrieve a value from a variable <strong>within</strong> the structure. It essentially tells the code to &#8216;look inside&#8217; the struct and find the variable.</p>
<p><strong>Note:</strong> When inserting integer, double, float, or long values into a variable, make sure you use the &#8216;&amp;&#8217; symbol beforehand.</p>
<li>Assign last_node to be the node you&#8217;ve just inserted to (as you will be moving on to the next node afterwards:</li>
<pre class="brush:c">/* This is important as you might be at the end of the list */
current_node -&gt; next_node = NULL;
last_node = current_node;</pre>
</ol>
<p>These steps are relatively simple to follow and they outline the important parts of creating a simple single linked list using malloc and pointers.</p>
<h2>Displaying information from a Linked List</h2>
<p>This is very simple and only requires you to set the start node and what rules there are to loop through the list. The most basic version is thus:</p>
<pre class="brush:c">current_node = first_node;

while(current_node -&gt; next_node != NULL) {
    printf("One of the values in this node is: %d", current_node -&gt; i);

    /* Set the current_node to point to the next node in the list */
    current_node = current_node -&gt; next_node;
}</pre>
<p>This loop will begin at the head of the list, and work its way through each node as long as &#8216;current_node -&gt; next_node&#8217; is not empty (a.k.a the end of the list).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/programming/c/linked-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Array of Characters (Strings)</title>
		<link>http://www.the-undergraduate.co.uk/programming/array-of-characters-strings/</link>
		<comments>http://www.the-undergraduate.co.uk/programming/array-of-characters-strings/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 19:29:13 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[array of character]]></category>
		<category><![CDATA[C89]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=246</guid>
		<description><![CDATA[Strings in C are handled differently to standard Java as there is no set &#8216;String&#8217; library. The following example will...]]></description>
			<content:encoded><![CDATA[<p>Strings in C are handled differently to standard Java as there is no set &#8216;String&#8217; library. The following example will show how to make a simple string in C89 C.</p>
<pre class="brush:c">
char array[5] = "Test\0";
</pre>
<p><b>Note:</b> Every string ends in a &#8216;Null Terminator&#8217; which is shown by a &#8216;\0&#8242;. If you do not add this at the end of your string, C will actually add one for you. However, this acts as an element within the array so if you don&#8217;t add it, make sure that the fixed size is one more than the number of characters (including white spaces).</p>
<p>Outputting the elements of a string in one consecutive line requires &#8216;%s&#8217; in the output.</p>
<pre class="brush:c">
printf("My array is: %s", array);
</pre>
<p>Output:</p>
<pre>My array is: Test</pre>
<p><span id="more-246"></span>When printing the array, there is no need to display particular elements (i.e. array[0]) as the variable &#8216;array&#8217; itself is a pointer to the initial element within itself. Using %s then goes through the entire array.</p>
<h2>White Spaces</h2>
<p>When a string contains white space (e.g. spaces within a sentence) the output will not complete the string after the first instance of white space, as it classes it as a terminator. In order to do this, you will need to use regular expressions.</p>
<pre class="brush:c">
printf("My array is: %[A-Za-z ]", array);
</pre>
<p>The REGEX within the square brackets tells the program to output any letters from A-Z, a-z, and also white spaces.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/programming/array-of-characters-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create an array of Strings</title>
		<link>http://www.the-undergraduate.co.uk/programming/c/create-an-array-of-strings/</link>
		<comments>http://www.the-undergraduate.co.uk/programming/c/create-an-array-of-strings/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 17:45:06 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[array of string]]></category>
		<category><![CDATA[malloc]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=236</guid>
		<description><![CDATA[Creating a string in ANSI C is very simple, as it is simply an array of characters. However, creating an...]]></description>
			<content:encoded><![CDATA[<p>Creating a string in ANSI C is very simple, as it is simply an array of characters. However, creating an array that holds strings is a little bit more tricky. This utilises C&#8217;s malloc() library.</p>
<p>In order to create an array of strings, you first need two things. You need the actual array container itself, which is a pointer to a pointer of type &#8216;char&#8217;. You will also need a pointer to a char. </p>
<pre class="brush:c">
/* This is the array that currently has no set size */
char** string_array;

/* Note that no size has been set yet for this */
char* string;
</pre>
<p>Now that you have these two chars, you can use malloc() to designate blocks of memory, and add some text for the first string:</p>
<pre class="brush:c">
string = (char *)malloc(6 * sizeof(char));

/* strcpy() places text into the string */
strcpy(string, "Hello");
</pre>
<p><span id="more-236"></span><b>Note:</b> When allocating blocks of memory for an array of characters, you will need to know how many characters there are going to be. In this case, I have allocated 6 blocks of memory. This is to hold each letter in the string, and one more for the null terminator (&#8216;\0&#8242;);</p>
<p>You then need to allocate memory for the array itself to hold a set number of elements. In this case, it will only be two elements:</p>
<pre class="brush:c">
*string_array = (char *)malloc(2 * sizeof(char *));
</pre>
<p>Now you can add the first string to the first element of the array (element 0):</p>
<pre class="brush:c">
/* Adds value of 'string' to element 0 of 'string_array' */
*string_array = string;
</pre>
<p>It is possible to then assign a new value to &#8216;string&#8217;, which is good if you are looping as it saves you having to create multiple strings. In this case, we want to assign a new value to &#8216;string&#8217; and place it into the next element of &#8216;string_array&#8217;:</p>
<pre class="brush:c">
string = (char *)malloc(6 * sizeof(char));

/* strcpy() places text into the string */
strcpy(string, "World");

*(string_array+1) = string;
</pre>
<p><b>Note:</b> I have placed the second string into element &#8217;1&#8242; of &#8216;string_array&#8217; by placing a &#8216;+1&#8242; after calling &#8216;string_array&#8217;. If you are using this in a loop, then you can do &#8216;+i&#8217; or whatever you have named the incrementing variable.</p>
<p>You have now just created a <i>very</i> simple array of Strings in ANSI C! If we print out this code, it will look like this:</p>
<pre class="brush:c">
printf("%s %s", *(string_array), *(string_array+1));
</pre>
<p>Output:</p>
<pre>Hello World</pre>
<p>Whole code:</p>
<pre class="brush:c">
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main() {
    /* This is the array that currently has no set size */
    char** string_array;

    /* Note that no size has been set yet for this */
    char* string;

    string = (char *)malloc(6 * sizeof(char));

    /* strcpy() places text into the string */
    strcpy(string, "Hello");

    *string_array = (char *)malloc(2 * sizeof(char *));

    /* Adds value of 'string' to element 0 of 'string_array' */
    *string_array = string;

    string = (char *)malloc(6 * sizeof(char));

    /* strcpy() places text into the string */
    strcpy(string, "World");

    *(string_array+1) = string;

    printf("%s %s", *(string_array), *(string_array+1));

    return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/programming/c/create-an-array-of-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XHTML and Brief History</title>
		<link>http://www.the-undergraduate.co.uk/markup/xhtml/xhtml-and-brief-history/</link>
		<comments>http://www.the-undergraduate.co.uk/markup/xhtml/xhtml-and-brief-history/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:36:24 +0000</pubDate>
		<dc:creator>ZesDa</dc:creator>
				<category><![CDATA[XHTML]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Markup]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=211</guid>
		<description><![CDATA[Overview eXtensible HyperText Markup Laguage (acronym XHTML) is a growing Markup Language (based on the XML markup language itself) that...]]></description>
			<content:encoded><![CDATA[<h2><span>Overview</span></h2>
<p>eXtensible HyperText Markup Laguage (acronym XHTML) is a growing Markup Language (based on the XML markup language itself) that extends that of SGML Markup Language currently well known as HTML (HyperText Markup Language) and defines how web pages are written and presented in Web Browsers. Whereas HTML maybe considered as a very flexible language to use when writing up websites, XHTML is based upon the XML standard whereby standard are more restrictive. This in turn requires pages to be written in a well formed and structured way in order to pass the online <a href="http://validator.w3.org/">validation services offered.</a></p>
<p><span id="more-211"></span></p>
<h2><span>Document Type Declaration</span></h2>
<pre>
&lt;!DOCTYPE HTML
    PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;       //Note for  XHTML 1.1 DTD
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;</pre>
<h2><span>History</span></h2>
<p>XHTML was developed to be a step in the right direction for the Web by working on a language which would be fully compatible and compliant with Web Browsers and the HTML 4 specification. By using the XML standard (approved in 1998 <a href="http://www.w3.org/XML/">link</a>) the HTML language would hopefully be more (ideally completely) compatible XML tools, servers and proxies would be able to transform content, as necessary, for constrained devices such as mobile phones as well as other mobile devices.</p>
<p>For any webpage to be written within XHTML (Transitional or Strict) and pass validation, there must be no styling elements within the XHTML page itself. Whereby these styling elements can be written into a separate styling file (such as CSS or XMS files) and referenced from the XHTML page.</p>
<p>XHTML 1.0 became a World Wide Web Consortium (W3C) Recommendation on January 26, 2000. XHTML 1.1 became a W3C Recommendation on May 31, 2001. XHTML5 is undergoing development as of September 2009, as part of the HTML5 specification. <a href="http://www.w3.org/TR/xhtml1/">link</a>.</p>
<h2><span>Relevent Extensions</span></h2>
<p>.xhtml, .xht, .xml, .html, .htm</p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/markup/xhtml/xhtml-and-brief-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Undergrad Developers</title>
		<link>http://www.the-undergraduate.co.uk/general/undergrad-developers/</link>
		<comments>http://www.the-undergraduate.co.uk/general/undergrad-developers/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 16:01:22 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=203</guid>
		<description><![CDATA[The Developers section of the Undergraduate has now been put live. This section is for showcasing current and past projects...]]></description>
			<content:encoded><![CDATA[<p>The Developers section of the Undergraduate has now been put live.</p>
<p>This section is for showcasing current and past projects by the users of this website.</p>
<p>URL: <a href="http://www.the-undergraduate.co.uk/dev">http://www.the-undergraduate.co.uk/dev</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/general/undergrad-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP include() and require()</title>
		<link>http://www.the-undergraduate.co.uk/scripting/php/php-include-and-require/</link>
		<comments>http://www.the-undergraduate.co.uk/scripting/php/php-include-and-require/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 22:52:01 +0000</pubDate>
		<dc:creator>Pyro</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[require]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=178</guid>
		<description><![CDATA[This post will continue my work in explaining some of the basic in-built functions of PHP. This time around, I...]]></description>
			<content:encoded><![CDATA[<p>This post will continue my work in explaining some of the basic in-built functions of PHP. This time around, I will take you through the include() and require() functions, and explain their similarities and differences and pros and cons respectively.<br />
<span id="more-178"></span></p>
<h2><span>The include() statement</span></h2>
<p>Essentially, it is like the echo command in that it will output the contents of files to the php page. Text files for example will be displayed on the page. PHP files are also displayed on the page, but it renders to HTML beforehand, and you can&#8217;t see the actual code. This is a fact that many PHP developers use on a daily basis. Including a PHP file is effectively the same thing as if the contents of that file had been written into the main PHP file.</p>
<p>For example, if I had a PHP file called echo.php</p>
<pre class="brush:php">&lt;?php
      echo("hello there");
?&gt;</pre>
<p>and another file called main.php</p>
<pre class="brush:php">&lt;?php
      include("echo.php");
?&gt;</pre>
<p>Output:</p>
<pre>
hello there
</pre>
<p>This, essentially (on a virtual level) pastes the echo statement into the middle of the main.php file. This can be seen as basic Object Oriented scripting within PHP.</p>
<p>What makes this very useful in larger projects is that if you have a website where the content changes very frequently, you could have your main.php file display the header and footer and stuff and include a content.php file in the middle. In which case, instead of having to sift through a potentially large amount of code to find your content, you only have to change the content.php file. This is used for efficiency and for the ability to write thousands of complicated and messy functions in one file and reduce it to a single line include statement in the file where the functions are required.</p>
<p>If an include() statement fails, i.e. if the file does not exist, the include will generate an error of level E_WARNING. I will go through error levels in detail at some other time, but for now it is suffice to say that this will post a warning to your page and continue to execute the PHP script. This can be insecure for larger projects where the scripts may then generate errors from functions not existing, which could result in sensitive data being posted to anybody who visits the page.</p>
<h2><span>The require() statement</span></h2>
<p>It is exactly the same in functionality as the include() statement, but if it fails, it will generate an error of level E_ERROR which is seen by PHP as a fatal run-time error. This will write the error message to the screen, and then halt execution of the script completely. Therefore, it is much more secure.</p>
<p>So why use include() at all? Why not just use require() all the time if it&#8217;s so much more secure?</p>
<p>Because, include and require both handle errors in different ways, one or the other is more preferable in different scenarios. For example, when handling sensitive data in secure e-commerce transactions for example, you want the scripts to terminate to prevent things going disastrously wrong so that you don&#8217;t end up pulling silly amounts of money out of someone&#8217;s bank account or displaying bank details and database passwords etc on the page for the world to see. In this case, you would use require(). You would probably then want the page to catch the error, terminate scripts and redirect to a &#8220;safe&#8221; page which apologises profusely for the mess-up and promises that the issue will be resolved as soon as possible.</p>
<p>However, for other less critical projects, it is likely that you will want the page to continue displaying content so that the site can function as normally as possible. You&#8217;d catch the error (this will be covered in future PHP posts) and display an error message to the user saying &#8220;technical difficulties&#8221; or whatever and let the site get on with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/scripting/php/php-include-and-require/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inline CSS</title>
		<link>http://www.the-undergraduate.co.uk/markup/css/inline-css/</link>
		<comments>http://www.the-undergraduate.co.uk/markup/css/inline-css/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 22:25:17 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[inline]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[tag]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=181</guid>
		<description><![CDATA[Some people are not aware that CSS can be used within HTML itself, other than just an &#8216;add-on&#8217;. It is...]]></description>
			<content:encoded><![CDATA[<p>Some people are not aware that CSS can be used within HTML itself, other than just an &#8216;add-on&#8217;. It is very simple, and can often save a lot of space if only small style tweaks are required.</p>
<p>Example:</p>
<pre class="brush:html">
&lt;div style="background: #CDCDCD; font-weight: bold;"&gt;
    Test.
&lt;/div&gt;
</pre>
<p>Outcome:</p>
<div style="background: #CDCDCD; font-weight: bold;">
    Test.
</div>
<p>It is very important to remember that the CSS can only lie within the style=&#8221;" element of a tag. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/markup/css/inline-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interactivity with HTML Elements</title>
		<link>http://www.the-undergraduate.co.uk/markup/css/interactivity-html-elements/</link>
		<comments>http://www.the-undergraduate.co.uk/markup/css/interactivity-html-elements/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 22:17:45 +0000</pubDate>
		<dc:creator>JAG</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[div class]]></category>
		<category><![CDATA[div id]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[id]]></category>

		<guid isPermaLink="false">http://www.the-undergraduate.co.uk/?p=157</guid>
		<description><![CDATA[While there are many different aspects to CSS that will edit the looks of a webpage as a whole, there...]]></description>
			<content:encoded><![CDATA[<p>While there are many different aspects to CSS that will edit the looks of a webpage as a whole, there are several HTML elements that need to be looked at manually. Firstly we will look at DIV classes and id&#8217;s. These are two very important aspects of DIVs as they represent two different ways HTML will look at the DIV.</p>
<p></p>
<h2><span>DIV Classes</span></h2>
<p>A DIV class represents a non-unique identifier for the HTML code. What this means is that you may have multiple DIVs on one page with the same class. In essence, they belong to the same &#8216;family&#8217;, and share design traits (omitting dimensions and positions). In CSS, when looking at classes, they are represented with a full stop (&#8216;.&#8217;).</p>
<p><span id="more-157"></span></p>
<pre class="brush:css">.my_class_1 {
    background: #ffffff;
}

.my_class_2 {
    background: #000000;
}</pre>
</p>
<p>This is a very simple example of how two different classes have different aspects to them. In order to apply these effects to a DIV, you simply need to add the &#8216;class&#8217; inside the tag:</p>
<pre class="brush:html">&lt;div class="my_class_1"&gt;
    This is a class test...
&lt;/div&gt;</pre>
<p>This class can be applied to as many DIV elements on a single page as you want, but if everything looks the same, the page can look &#8216;bland&#8217;. This is where DIV ID tags come in&#8230;</p>
<p><!--more--><br />
<h2><span>DIV IDs</span></h2>
<p>These work in very similar ways to Classes in DIVs, but are limited to one ID per element. This means that you are not allowed to have more than one DIV on a single page with the same ID. The idea behind this is to allow the user to specify different design aspects to different DIV tags without calling more classes than you need to.</p>
<p>In CSS, an ID is represented as a hash (&#8216;#&#8217;):</p>
<pre class="brush:css">#my_id_1 {
    background: #ffffff;
}

#my_id_2 {
    background: #000000;
}</pre>
<p>As you can see, it works in almost an identical way to DIV classes. In HTML, the code to apply an ID to a DIV would be:</p>
<pre class="brush:html">&lt;div id="my_id_1"&gt;
    This is an ID test...
&lt;/div&gt;</pre>
<p>So, that&#8217;s the basic idea of using Class and ID inside DIV tags in HTML to their full advantage&#8230; Separately.</p>
<p>Due to CSS setting aspects of Classes and IDs separately, you are able to set different styles to them. What does this mean? Well, it means that you are in fact able to &#8216;merge&#8217; these two styles together.</p>
<p><!--more--><br />
<h2><span>Merging</span></h2>
<p>Imagine that you have a basic web page layout, with say, 4 DIVs. Now we can tell from this that we want 4 different ID styles within the CSS. When it comes to classes, we can have a range from 1 to 4. In this case, we will have only 1. Now, imagine that this is a rather formal web page and everything must conform to a certain set of design rules. We can use the DIV class to set up a &#8216;standard&#8217; design for each DIV. This will make sure that the general aspect of the DIVs together are the same.</p>
<p>Each ID can then be used to set smaller and individual styles for each DIV. If each DIV is going to represent a different aspect of the web page, they are going to need to be distiguishable from one another. From this idea, we can come up with a simple set of CSS to allow the style to conform to the standard of the web page:</p>
<pre class="brush:css">/* CLASSES  */

.div_class {
    background: #CDCDCD;
}

/* IDs */

#id_1 {
    font-weight: bold;
}

#id_2 {
    text-decoration: underline;
}

#id_3 {
    text-align: right;
}

#id_4 {
    text-align: left;
}</pre>
<p>With the CSS sorted, you can now apply these styles to the DIVs within the HTML:</p>
<pre class="brush:html">&lt;div id="id_1" class="div_class"&gt;
     DIV ID = 1.
&lt;div&gt;

&lt;div id="id_2" class="div_class"&gt;
     DIV ID = 2.
&lt;div&gt;

&lt;div id="id_3" class="div_class"&gt;
     DIV ID = 3.
&lt;div&gt;

&lt;div id="id_4" class="div_class"&gt;
     DIV ID = 4.
&lt;div&gt;</pre>
<p>The output should look like:</p>
<div style="background: rgb(205, 205, 205) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; font-weight: bold;" mce_style="background: #CDCDCD; font-weight: bold;">DIV ID = 1;</div>
<p>&#8212;&#8212;</p>
<div style="background: rgb(205, 205, 205) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-decoration: underline;" mce_style="background: #CDCDCD; text-decoration: underline;">DIV ID = 2;</div>
<p>&#8212;&#8212;</p>
<div style="background: rgb(205, 205, 205) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: right;" mce_style="background: #CDCDCD; text-align: right;">DIV ID = 3;</div>
<p>&#8212;&#8212;</p>
<div style="background: rgb(205, 205, 205) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;" mce_style="background: #CDCDCD; text-align: left;">DIV ID = 4;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.the-undergraduate.co.uk/markup/css/interactivity-html-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
