<?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>Bull3t's Blog &#187; Code Snippets</title>
	<atom:link href="http://blog.bull3t.me.uk/archives/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bull3t.me.uk</link>
	<description>The rants and raves of the interweb.</description>
	<lastBuildDate>Mon, 19 Apr 2010 15:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Code Snippet: Tag cloud</title>
		<link>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-tag-cloud/</link>
		<comments>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-tag-cloud/#comments</comments>
		<pubDate>Wed, 08 Aug 2007 12:50:19 +0000</pubDate>
		<dc:creator>Bull3t</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tags]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.bull3t.me.uk/archives/uncategorized/code-wednesday-tag-cloud/</guid>
		<description><![CDATA[<p>Here is another post containing a snippet of code that you can use in your own project or just so that you can store it in your "Useless Snippets Folder" on your Desktop. You can view all of the older code snippet articles by browsing the <a href="http://blog.bull3t.me.uk/archives/category/code-snippets/" title="Other Code Snippets articles.">code snippet category list</a>.</p>
<p>This code can be used to make a simple and easy tag cloud for your categories or tags on your own website or blog. It uses a simple mathematical sum to calculate a percentage for the font size of each tag and then returns it [&#8230;]</p>]]></description>
			<content:encoded><![CDATA[<p>Here is another post containing a snippet of code that you can use in your own project or just so that you can store it in your "Useless Snippets Folder" on your Desktop. You can view all of the older code snippet articles by browsing the <a href="http://blog.bull3t.me.uk/archives/category/code-snippets/" title="Other Code Snippets articles.">code snippet category list</a>.</p>
<p>This code can be used to make a simple and easy tag cloud for your categories or tags on your own website or blog. It uses a simple mathematical sum to calculate a percentage for the font size of each tag and then returns it in a XHTML-compliant, inline list. The function requires an array of the tags in the format: "$tags['tag_name'] = tag_count;", when <em>tag_name</em> is the name of the tag and <em>tag_count</em> is the amount of instances the tag has.</p>
<p>Anyway, here is the code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p116code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1163"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p116code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Error: no $tag argument was specified.</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$max_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$min_size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$largest</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/max"><span style="color: #990000;">max</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array_values"><span style="color: #990000;">array_values</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$smallest</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/min"><span style="color: #990000;">min</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array_values"><span style="color: #990000;">array_values</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$range</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$largest</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$smallest</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$range</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$range</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$step</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$max_size</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$min_size</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$range</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;ul style=&quot;list-style: none; padding: 0; margin: 0;&quot;&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$min_size</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$smallest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$step</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li style=&quot;display: inline; padding: 5px;&quot;&gt;&lt;a href=&quot;#&quot; style=&quot;font-size: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'%&quot; title=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' ('</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Return: return the output content, conating the formatted tags.</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>For example, you could use the function as follows:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p116code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1164"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p116code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">21</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">54</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag3'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">42</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag4'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag5'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">32</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag6'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag7'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">54</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag8'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">35</span><span style="color: #339933;">;</span>
&nbsp;
<a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Which would output the following:</p>
<ul style="list-style: none; padding: 0; margin: 0;">
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 132.14285714286%" title="tag1 (21)">tag1</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 250%" title="tag2 (54)">tag2</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 207.14285714286%" title="tag3 (42)">tag3</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 100%" title="tag4 (13)">tag4</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 171.42857142857%" title="tag5 (32)">tag5</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 100%" title="tag6 (12)">tag6</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 250%" title="tag7 (54)">tag7</a></li>
<li style="display: inline; padding: 5px;"><a href="#" style="font-size: 182.14285714286%" title="tag8 (35)">tag8</a></li>
</ul>
<div class="clear"></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-tag-cloud/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Simple contact form</title>
		<link>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-simple-contact-form/</link>
		<comments>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-simple-contact-form/#comments</comments>
		<pubDate>Wed, 01 Aug 2007 09:31:01 +0000</pubDate>
		<dc:creator>Bull3t</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Contact]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.bull3t.me.uk/archives/code-wednesday/code-wednesday-simple-contact-form/</guid>
		<description><![CDATA[<p>Here is another post containing a snippet of code that you can use in your own project or just so that you can store it in your "Useless Snippets Folder" on your Desktop. You can view all of the older code snippet articles by browsing the <a href="http://blog.bull3t.me.uk/archives/category/code-snippets/" title="Other Code Snippets articles.">code snippet category list</a>.</p>
<p>This time I will be showing you how to create yourself a very simple contact form for use on your blog or website. It will consist of just two files &#8211; one being the PHP script to send the mail and the other being the [&#8230;]</p>]]></description>
			<content:encoded><![CDATA[<p>Here is another post containing a snippet of code that you can use in your own project or just so that you can store it in your "Useless Snippets Folder" on your Desktop. You can view all of the older code snippet articles by browsing the <a href="http://blog.bull3t.me.uk/archives/category/code-snippets/" title="Other Code Snippets articles.">code snippet category list</a>.</p>
<p>This time I will be showing you how to create yourself a very simple contact form for use on your blog or website. It will consist of just two files &#8211; one being the PHP script to send the mail and the other being the HTML that can be used to send the mail &#8211; and I will explain how to use them and what they do.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p114code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1147"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p114code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;you@yourdomain.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// E-mail address to send to.</span>
	<span style="color: #000088;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[Bull3t's Blog] Simple Contact Form: &quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Subject prefix.</span>
&nbsp;
	<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$prefix</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subject'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>E-Mail: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Message:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;Thankyou, &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;. Your form was successfully submitted.&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">&quot;There was an error whilst sending your message, please try again later.&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This is the PHP script that will be used to send the mail to you, all you need to do is change the <em>$to</em> variable to your e-mail address and the <em>$prefix</em> variable to whatever you want the prefix of the subject to be. Then save it as send.php and upload it to your website.</p>
<p>The next step is to add the form itself, to do this you need to save a simple HTML file containing a form, which, when submitted, sends the information from the text boxes to the <em>send.php</em> file and in turn, sending the mail.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p114code8'); return false;">View Code</a> HTML4STRICT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1148"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p114code8"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;&lt;<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;send.php&quot;</span>&gt;</span>
	Name: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;19&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
	E-Mail Address: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;19&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
	Subject: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;subject&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;19&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
	Message: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/textarea.html"><span style="color: #000000; font-weight: bold;">textarea</span></a> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/textarea.html"><span style="color: #000000; font-weight: bold;">textarea</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span>&gt;</span>	
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></pre></td></tr></table></div>

<p>As you can see, all that it consists of is a series of text boxes for your user to type in their details, quite simple really, and there is no need for JavaScript. This file should be saved as <em>index.html</em> and uploaded to your website in the same directory as <em>send.php</em>. Then navigate to the <em>index.html</em> on your website and test the form, if all went well you should get a page telling you it was successfully sent, if you receive an error message, however you may want to check with your host to see whether they allow the <a href="http://uk.php.net/manual/en/function.mail.php">PHP mail</a> function.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-simple-contact-form/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Snippet: Remote filesize function</title>
		<link>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-remote-filesize-function/</link>
		<comments>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-remote-filesize-function/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 01:21:43 +0000</pubDate>
		<dc:creator>Bull3t</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.bull3t.me.uk/archives/code-wednesday/code-wednesday-1-php-remote-filesize-function</guid>
		<description><![CDATA[<p>I am beginning to publish posts containing snippets of code that you can use in your own project or just so that you can store it in your "Useless Snippets Folder" on your Desktop. Nevertheless, I wanted to do something on my blog to liven it up a little. View more <a href="http://blog.bull3t.me.uk/archives/category/code-snippets/" title="Other Code Snippet articles.">code snippets</a>.</p>
<p>For the first one, here is a little script that I found extremely useful, it allows you to retrieve the file size of a file located on a remote server using a HTTP, HTTPS, FTP or FTPS URI, quickly and easily. This [&#8230;]</p>]]></description>
			<content:encoded><![CDATA[<p>I am beginning to publish posts containing snippets of code that you can use in your own project or just so that you can store it in your "Useless Snippets Folder" on your Desktop. Nevertheless, I wanted to do something on my blog to liven it up a little. View more <a href="http://blog.bull3t.me.uk/archives/category/code-snippets/" title="Other Code Snippet articles.">code snippets</a>.</p>
<p>For the first one, here is a little script that I found extremely useful, it allows you to retrieve the file size of a file located on a remote server using a HTTP, HTTPS, FTP or FTPS URI, quickly and easily. This is useful because the PHP <a href="http://www.php.net/filesize/">filesize()</a> function does not always accept HTTP wrappers.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p107code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10711"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code" id="p107code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> remotefilesize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$sch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_SCHEME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;http&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;https&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;ftp&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;ftps&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// Error: unrecognized URI scheme.</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;http&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;https&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_change_key_case"><span style="color: #990000;">array_change_key_case</span></a><span style="color: #009900;">&#40;</span>get_headers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> CASE_LOWER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/array_key_exists"><span style="color: #990000;">array_key_exists</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-length&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// Error: no 'content-length' header.</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;content-length&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Return: $headers[&quot;content-length&quot;] value.</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ftp&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;ftps&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_HOST<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$port</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_PORT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_PATH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_USER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/parse_url"><span style="color: #990000;">parse_url</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> PHP_URL_PASS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$server</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// Error: invalid FTP URI.</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">21</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;anonymous&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;phpos@&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sch</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;ftp&quot;</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$ftpid</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ftp_connect"><span style="color: #990000;">ftp_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$server</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;ftps&quot;</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$ftpid</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ftp_ssl_connect"><span style="color: #990000;">ftp_ssl_connect</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$server</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$ftpid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// Error: could not connect to the FTP server.</span>
&nbsp;
		<span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ftp_login"><span style="color: #990000;">ftp_login</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftpid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$login</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// Error: could not login to the FTP server.</span>
&nbsp;
		<span style="color: #000088;">$ftpsize</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ftp_size"><span style="color: #990000;">ftp_size</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftpid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftpsize</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>  <span style="color: #666666; font-style: italic;">// Error: could not size the FTP file.</span>
&nbsp;
		<a href="http://www.php.net/ftp_close"><span style="color: #990000;">ftp_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftpid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ftpsize</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Return: $ftpsize value.</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This function takes one argument; <strong>$url</strong>, which is required and should contain the URL of the file to retrieve the size of. The output will be returned as a string in bytes, or if an error was encountered it will return false.</p>
<p>This code can be used accordingly:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p107code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p10712"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p107code12"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> remotefilesize<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.google.co.uk/images/logo.gif&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; bytes.&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This example would return: "8706 bytes.". As that is the size, in bytes of the Google logo.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bull3t.me.uk/archives/code-snippets/code-snippet-remote-filesize-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
