<?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>John Ciacia</title>
	<atom:link href="http://www.johnciacia.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnciacia.com</link>
	<description>Science, Technology, and Beyond</description>
	<lastBuildDate>Mon, 08 Mar 2010 04:57:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>atime, mtime, and ctime</title>
		<link>http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/</link>
		<comments>http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 04:57:50 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=489</guid>
		<description><![CDATA[On traditional Unix-style file systems three timestamps are associated with each file. These timestamps are atime, ctime, and mtime. Most people understand atime as &#8220;access time.&#8221; A file is accessed when its content is viewed or is executed. ctime and mtime generate confusion since &#8220;change time&#8221; and &#8220;modification time&#8221; seem synonymous. However, what you need [...]]]></description>
			<content:encoded><![CDATA[<p>On traditional Unix-style file systems three timestamps are associated with each file. These timestamps are atime, ctime, and mtime. Most people understand atime as &#8220;access time.&#8221; A file is accessed when its content is viewed or is executed. ctime and mtime generate confusion since &#8220;change time&#8221; and &#8220;modification time&#8221; seem synonymous. However, what you need to focus on is <em>what</em> is being changed. The mtime value is updated when the actual contents of the file are changed. However, updating mtime, also updates ctime. This does not mean an update to ctime will cause an update to mtime. The ctime value is updated when the files inode or change to the files content are made. For example:</p>
<blockquote><p># cat foo<br />
Hello, World</p></blockquote>
<p>Will update the files atime, but it will not effect the ctime or mtime.</p>
<blockquote><p># chmod 777 foo</p></blockquote>
<p>Will update the files ctime but not the files atime or mtime.</p>
<blockquote><p># echo &#8220;Goodbye, World!&#8221; > foo</p></blockquote>
<p>Will update the files ctime and mtime but not the files atime.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/&amp;title=atime%2C+mtime%2C+and+ctime" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/&amp;title=atime%2C+mtime%2C+and+ctime" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/&amp;title=atime%2C+mtime%2C+and+ctime" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/&amp;title=atime%2C+mtime%2C+and+ctime" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/&amp;submitHeadline=atime%2C+mtime%2C+and+ctime&amp;submitSummary=On%20traditional%20Unix-style%20file%20systems%20three%20timestamps%20are%20associated%20with%20each%20file.%20These%20timestamps%20are%20atime%2C%20ctime%2C%20and%20mtime.%20Most%20people%20understand%20atime%20as%20%22access%20time.%22%20A%20file%20is%20accessed%20when%20its%20content%20is%20viewed%20or%20is%20executed.%20ctime%20and%20mtime%20generate%20confusion%20since%20%22change%20time%22%20and&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/&amp;title=atime%2C+mtime%2C+and+ctime" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=atime%2C+mtime%2C+and+ctime+-+http://www.johnciacia.com/489+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/03/atime-mtime-and-ctime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging MySQL issues in PHP</title>
		<link>http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/</link>
		<comments>http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 18:19:16 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=477</guid>
		<description><![CDATA[Possibly the most common issue users have with PHP is working with MySQL. Executing a query requires a three step process:

Connecting to your database server.
Selecting a database.
Executing the query.

When a query fails, many users don&#8217;t know where to begin debugging. This guide outlines my debugging procedure.
Verifying Database Connectivity
1. A database connection is generally established using [...]]]></description>
			<content:encoded><![CDATA[<p>Possibly the most common issue users have with PHP is working with MySQL. Executing a query requires a three step process:</p>
<ul>
<li>Connecting to your database server.</li>
<li>Selecting a database.</li>
<li>Executing the query.</li>
</ul>
<p>When a query fails, many users don&#8217;t know where to begin debugging. This guide outlines my debugging procedure.</p>
<h2>Verifying Database Connectivity</h2>
<p>1. A database connection is generally established using <a href="http://us3.php.net/manual/en/function.mysql-connect.php">mysql_connect</a>. As the documentation states: </p>
<blockquote><p>Returns a MySQL link identifier on success, or FALSE on failure.</p></blockquote>
<p>Thus the first thing to check is the value mysql_connect is returning. There are several ways to test the output. Assuming you are using the following line of code to connect to your database </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');</span></pre>
</div>
</div>
<p>You can do as the PHP manual suggests: </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';</span></pre>
</div>
</div>
<p>or for something quick and dirty: </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">var_dump($link);</span></pre>
</div>
</div>
<p>The former will output <em>Connected successfully</em> on success and the latter will output something similar to <em>resource(2) of type (mysql link)</em> If this is the case, you know mysql_connect is returning a resource and your issue probably has nothing to do with establishing a connection to the database. If the former outputs <em>Could not connect:</em> or the latter outputs <em>bool(false)</em> you have a problem connecting to your database server. In this case you should:</p>
<ul>
<li>Verify your parameter order is correct &#8211; <em>server</em>, <em>username</em>, <em>password</em>.</li>
<li>Verify that the credentials are correct.</li>
<li>Verify your mysql server is actually running&#8230;</li>
</ul>
<p>If you are still having issues connecting to your database, your problem is beyond the discussion of this guide.</p>
<h2>Database Selection</h2>
<p>2. Once you have verified connectivity with the server, verify a database has been selected. Database selection is accomplished using <a href="http://us3.php.net/manual/en/function.mysql-select-db.php">mysql_select_db</a>. This function will return <em>true</em> on success and <em>false</em> on failure. As done in the previous section we want to check which value mysql_select_db is returning. Assuming you have the following code: </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$db_selected = mysql_select_db('foo', $link);</span></pre>
</div>
</div>
<p>You can either use </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}</span></pre>
</div>
</div>
<p>or simply </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">var_dump($db_selected)</span></pre>
</div>
</div>
<p>If you receive <em>Can&#8217;t use foo</em> or <em>bool(false)</em> your issue is with selecting your database.</p>
<ul>
<li>Verify the database you are selecting is spelled correctly.</li>
<li>Verify the database exists.</li>
<li>Verify the user you connected to the database server with has access to this particular database.</li>
</ul>
<h2>The Query</h2>
<p>3. If you have successfully established a connection with the database server and have selected a database, and your query still does not work, then the problem is most likely your query itself. Assuming you use are using the following code to query your database: </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$result = mysql_query('SELECT * WHERE 1=1');</span></pre>
</div>
</div>
<p>You can see more information about your error using <a href="http://us3.php.net/manual/en/function.mysql-error.php">mysql_error()</a>. Here is how: </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
    die('Invalid query: ' . mysql_error());
}</span></pre>
</div>
</div>
<p>This will usually result in a Googleable error or you can refer to the MySQL documentation for the <a href="http://dev.mysql.com/doc/refman/5.1/en/error-handling.html">MySQL error codes</a>. Unfortunately, most queries are not as simple as the one in the example above. They can usually span several lines and almost always contain variables. If this is the case, I echo my query and execute the output it in phpMyAdmin. phpMyAdmin usually gives me an error that is easily understandable, like &#8220;Unknown column name foo.&#8221; </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$query = &quot;SELECT * FROM foo WHERE id=$id&quot;;
die($query);
...</span></pre>
</div>
</div>
<p>This will print your query exactly as it is executed. Many times unescaped characters in variables (which may cause <a href="http://forum.codecall.net/security-tutorials/4422-php-sql-injections.html">SQL Injections</a>) will cause your query to fail. Echoing your query will help catch this. Lastly, try not to use a keyword as a database name or column. For example, if you named a column <em>select</em> your query might look like </p>
<div class="quote">SELECT * FROM select WHERE foo=bar</div>
<p> The error here is obvious. MySQL interpreters select as a keyword and not as a column name. To avoid this, use backticks around your table and column names.
<div class="quote">SELECT * FROM `select` WHERE `foo`=&#8217;bar&#8217;</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/&amp;title=Debugging+MySQL+issues+in+PHP" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/&amp;title=Debugging+MySQL+issues+in+PHP" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/&amp;title=Debugging+MySQL+issues+in+PHP" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/&amp;title=Debugging+MySQL+issues+in+PHP" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/&amp;submitHeadline=Debugging+MySQL+issues+in+PHP&amp;submitSummary=Possibly%20the%20most%20common%20issue%20users%20have%20with%20PHP%20is%20working%20with%20MySQL.%20Executing%20a%20query%20requires%20a%20three%20step%20process%3A%0D%0A%0D%0A%0D%0A%09Connecting%20to%20your%20database%20server.%0D%0A%09Selecting%20a%20database.%0D%0A%09Executing%20the%20query.%0D%0A%0D%0A%0D%0AWhen%20a%20query%20fails%2C%20many%20users%20don%27t%20know%20where%20to%20begin%20debugging.%20This%20guide%20outl&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/&amp;title=Debugging+MySQL+issues+in+PHP" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Debugging+MySQL+issues+in+PHP+-+http://www.johnciacia.com/477+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/debugging-mysql-issues-in-php-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>isset vs. empty</title>
		<link>http://www.johnciacia.com/2010/01/isset-vs-empty/</link>
		<comments>http://www.johnciacia.com/2010/01/isset-vs-empty/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 04:32:48 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[empty]]></category>
		<category><![CDATA[isset]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=466</guid>
		<description><![CDATA[Many people tend to view these two functions as opposites, causing necessary debugging. This issue frequently occurs when validating forms.
isset()
From the PHP manual:
isset — Determine if a variable is set and is not NULL
In other words, a variable is set if it has been assigned a value other than NULL. If a variable is assigned [...]]]></description>
			<content:encoded><![CDATA[<p>Many people tend to view these two functions as opposites, causing necessary debugging. This issue frequently occurs when validating forms.</p>
<h2>isset()</h2>
<p>From the PHP manual:</p>
<blockquote><p>isset — Determine if a variable is set and is not NULL</p></blockquote>
<p>In other words, a variable <strong>is set</strong> if it has been assigned a value other than NULL. If a variable is assigned to be an empty string &#8211; it is set. The following code and output should illustrate my point.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">

</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">isset</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-reserved">NULL</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">isset</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">isset</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">isset</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>
<div class="quote">bool(false)<br />
bool(false)<br />
bool(true)<br />
bool(true)
</div>
<h2>empty()</h2>
<p>Again from the PHP manual:</p>
<blockquote><p>empty — Determine whether a variable is empty</p></blockquote>
<p>In other words, a variable is <strong>empty</strong> if it is an empty string, 0, &#8220;0&#8243;, false, NULL, array(), and an unset variable are all empty.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">

</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-reserved">NULL</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">0</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-reserved">false</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>
<div class="quote">bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)
</div>
<p>Now when you are validating forms to make sure a user did not leave a form field blank, it is probably best to use neither empty() or isset() (not that isset would work). Since it is possible your form might accept 0 as a valid answer. Therefore you should just check to make sure it is not an empty string.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">foo</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> == </span><span class="hl-quotes">&quot;</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">You must enter a value for foo!</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/01/isset-vs-empty/&amp;title=isset+vs.+empty" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/01/isset-vs-empty/&amp;title=isset+vs.+empty" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/01/isset-vs-empty/&amp;title=isset+vs.+empty" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/01/isset-vs-empty/&amp;title=isset+vs.+empty" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/01/isset-vs-empty/&amp;submitHeadline=isset+vs.+empty&amp;submitSummary=Many%20people%20tend%20to%20view%20these%20two%20functions%20as%20opposites%2C%20causing%20necessary%20debugging.%20This%20issue%20frequently%20occurs%20when%20validating%20forms.%0D%0A%0D%0Aisset%28%29%0D%0AFrom%20the%20PHP%20manual%3A%0D%0Aisset%20%E2%80%94%20Determine%20if%20a%20variable%20is%20set%20and%20is%20not%20NULL%0D%0AIn%20other%20words%2C%20a%20variable%20is%20set%20if%20it%20has%20been%20assigned%20a%20value%20ot&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/01/isset-vs-empty/&amp;title=isset+vs.+empty" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/01/isset-vs-empty/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=isset+vs.+empty+-+http://www.johnciacia.com/466+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/01/isset-vs-empty/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/isset-vs-empty/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Basic OCR</title>
		<link>http://www.johnciacia.com/2010/01/basic-ocr/</link>
		<comments>http://www.johnciacia.com/2010/01/basic-ocr/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 03:40:11 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[gd]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=454</guid>
		<description><![CDATA[This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there can be many collisions. A database is needed to compare [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there can be many collisions. A database is needed to compare output results of this script with known values.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">

</span><span class="hl-comment">/*</span><span class="hl-comment"> create a test image </span><span class="hl-comment">*/</span><span class="hl-code">
</span><span class="hl-var">$im</span><span class="hl-code"> = @</span><span class="hl-identifier">imagecreate</span><span class="hl-brackets">(</span><span class="hl-number">100</span><span class="hl-code">, </span><span class="hl-number">20</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">or</span><span class="hl-code"> </span><span class="hl-reserved">die</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Cannot Initialize new GD image stream</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$background_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$text_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagestring</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">1</span><span class="hl-code">, </span><span class="hl-number">5</span><span class="hl-code">, </span><span class="hl-number">5</span><span class="hl-code">,  </span><span class="hl-quotes">&quot;</span><span class="hl-string">Hello, World!</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-var">$text_color</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-comment">/*</span><span class="hl-comment">**
 * Assumptions:
 *   A monochrome image where characters are black
 *   A single character is connected
 *   Characters are disjointed by white space
 </span><span class="hl-comment">*/</span><span class="hl-code">

</span><span class="hl-var">$width</span><span class="hl-code"> = </span><span class="hl-identifier">imagesx</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$height</span><span class="hl-code"> = </span><span class="hl-identifier">imagesy</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;

</span><span class="hl-comment">/*</span><span class="hl-comment">**
 * Notes:
 *   The smaller the sample size the more accurate it will be,
 *   however, it will take longer. Larger images can use a larger
 *   sample size wihtout compromizing much accuracy.
 </span><span class="hl-comment">*/</span><span class="hl-code">
</span><span class="hl-var">$x_sample</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">;
</span><span class="hl-var">$y_sample</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">;

</span><span class="hl-var">$last</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
</span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-var">$i</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code"> &lt; </span><span class="hl-var">$width</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-var">$col</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;

    </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-var">$j</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$j</span><span class="hl-code"> &lt; </span><span class="hl-var">$height</span><span class="hl-code">; </span><span class="hl-var">$j</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-var">$col</span><span class="hl-brackets">[</span><span class="hl-var">$j</span><span class="hl-brackets">]</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorat</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-var">$i</span><span class="hl-code">, </span><span class="hl-var">$j</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">

    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-brackets">(</span><span class="hl-var">$current</span><span class="hl-code"> = </span><span class="hl-identifier">array_sum</span><span class="hl-brackets">(</span><span class="hl-var">$col</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> &gt; </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-var">$last</span><span class="hl-code"> == </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
            </span><span class="hl-var">$l</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
        </span><span class="hl-brackets">}</span><span class="hl-code">

        </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-var">$k</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$k</span><span class="hl-code"> &lt; </span><span class="hl-var">$height</span><span class="hl-code">; </span><span class="hl-var">$k</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
            </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-brackets">(</span><span class="hl-var">$l</span><span class="hl-code"> % </span><span class="hl-var">$x_sample</span><span class="hl-brackets">)</span><span class="hl-code"> == </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
                </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-brackets">(</span><span class="hl-var">$k</span><span class="hl-code"> % </span><span class="hl-var">$y_sample</span><span class="hl-brackets">)</span><span class="hl-code"> == </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
                    </span><span class="hl-var">$sample</span><span class="hl-code"> .= </span><span class="hl-var">$col</span><span class="hl-brackets">[</span><span class="hl-var">$k</span><span class="hl-brackets">]</span><span class="hl-code">;
                </span><span class="hl-brackets">}</span><span class="hl-code">
            </span><span class="hl-brackets">}</span><span class="hl-code">
        </span><span class="hl-brackets">}</span><span class="hl-code">

        </span><span class="hl-var">$l</span><span class="hl-code">++;
        </span><span class="hl-var">$last</span><span class="hl-code"> = </span><span class="hl-var">$current</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-var">$last</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">

    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-code">!</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$sample</span><span class="hl-brackets">)</span><span class="hl-code"> &amp;&amp; </span><span class="hl-var">$last</span><span class="hl-code"> == </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$sample</span><span class="hl-code"> . </span><span class="hl-quotes">&quot;</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
        </span><span class="hl-var">$sample</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>
<p>Output (each line represents a character)</p>
<div class="quote">00000011111100000000000000001000000000000000000010000000000000000011111100000000<br />
00000000011000000000000000001011000000000000000011010000000000000000010100000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
00000000011000000000000000001001000000000000000010010000000000000000011000000000<br />
000000000001000000000000000001100000000000000000010000000000<br />
00000011111100000000000000000110000000000000000001100000000000000011111100000000<br />
00000000011000000000000000001001000000000000000010010000000000000000011000000000<br />
00000000111100000000000000000100000000000000000010000000000000000000010000000000<br />
000000100001000000000000001111110000000000000000000100000000<br />
00000000011000000000000000001001000000000000000010100000000000000011111100000000<br />
00000001110100000000</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/01/basic-ocr/&amp;title=Basic+OCR" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/01/basic-ocr/&amp;title=Basic+OCR" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/01/basic-ocr/&amp;title=Basic+OCR" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/01/basic-ocr/&amp;title=Basic+OCR" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/01/basic-ocr/&amp;submitHeadline=Basic+OCR&amp;submitSummary=This%20is%20a%20very%20basic%20optical%20character%20recognition%20script%20written%20in%20PHP.%20This%20is%20untested%20and%20serves%20merely%20a%20proof%20of%20concept.%20As%20noted%20in%20the%20comments%2C%20adjusting%20the%20sample%20size%20can%20improve%20results%2C%20since%20with%20a%20large%20sample%20size%20on%20a%20small%20image%20there%20can%20be%20many%20collisions.%20A%20database%20is%20needed&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/01/basic-ocr/&amp;title=Basic+OCR" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/01/basic-ocr/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Basic+OCR+-+http://www.johnciacia.com/454+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/01/basic-ocr/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/basic-ocr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PHP and GD to add border to text</title>
		<link>http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/</link>
		<comments>http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:41:03 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[stroke]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=449</guid>
		<description><![CDATA[




		
			Submit this to Script &#38; Style
		
		
			Digg this!
		
		
			Share this on del.icio.us
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Buzz up!
		
		
			Share this on Reddit
		
		
			Share this on Technorati
		
		
			Tweet This!
		
		
			Subscribe to the comments for this post?
		





]]></description>
			<content:encoded><![CDATA[<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">/*</span><span class="hl-comment">*
 * Writes the given text with a border into the image using TrueType fonts.
 *</span><span class="hl-inlinedoc"> @author </span><span class="hl-comment">John Ciacia
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">image An image resource
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">size The font size
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">angle The angle in degrees to rotate the text
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">x Upper left corner of the text
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">y Lower left corner of the text
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">textcolor This is the color of the main text
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">strokecolor This is the color of the text border
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">fontfile The path to the TrueType font you wish to use
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">text The text string in UTF-8 encoding
 *</span><span class="hl-inlinedoc"> @param </span><span class="hl-comment">px Number of pixels the text border will be
 *</span><span class="hl-inlinedoc"> @see </span><span class="hl-url">http://us.php.net/manual/en/function.imagettftext.php</span><span class="hl-comment">
 </span><span class="hl-comment">*/</span><span class="hl-code">
</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">imagettfstroketext</span><span class="hl-brackets">(</span><span class="hl-code">&amp;</span><span class="hl-var">$image</span><span class="hl-code">, </span><span class="hl-var">$size</span><span class="hl-code">, </span><span class="hl-var">$angle</span><span class="hl-code">, </span><span class="hl-var">$x</span><span class="hl-code">, </span><span class="hl-var">$y</span><span class="hl-code">, &amp;</span><span class="hl-var">$textcolor</span><span class="hl-code">, &amp;</span><span class="hl-var">$strokecolor</span><span class="hl-code">, </span><span class="hl-var">$fontfile</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-code">, </span><span class="hl-var">$px</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">

    </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-var">$c1</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code">-</span><span class="hl-identifier">abs</span><span class="hl-brackets">(</span><span class="hl-var">$px</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-var">$c1</span><span class="hl-code"> &lt;= </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code">+</span><span class="hl-identifier">abs</span><span class="hl-brackets">(</span><span class="hl-var">$px</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-var">$c1</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code">
        </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-var">$c2</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-var">$y</span><span class="hl-code">-</span><span class="hl-identifier">abs</span><span class="hl-brackets">(</span><span class="hl-var">$px</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-var">$c2</span><span class="hl-code"> &lt;= </span><span class="hl-brackets">(</span><span class="hl-var">$y</span><span class="hl-code">+</span><span class="hl-identifier">abs</span><span class="hl-brackets">(</span><span class="hl-var">$px</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-var">$c2</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-code">
            </span><span class="hl-var">$bg</span><span class="hl-code"> = </span><span class="hl-identifier">imagettftext</span><span class="hl-brackets">(</span><span class="hl-var">$image</span><span class="hl-code">, </span><span class="hl-var">$size</span><span class="hl-code">, </span><span class="hl-var">$angle</span><span class="hl-code">, </span><span class="hl-var">$c1</span><span class="hl-code">, </span><span class="hl-var">$c2</span><span class="hl-code">, </span><span class="hl-var">$strokecolor</span><span class="hl-code">, </span><span class="hl-var">$fontfile</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">;

   </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-identifier">imagettftext</span><span class="hl-brackets">(</span><span class="hl-var">$image</span><span class="hl-code">, </span><span class="hl-var">$size</span><span class="hl-code">, </span><span class="hl-var">$angle</span><span class="hl-code">, </span><span class="hl-var">$x</span><span class="hl-code">, </span><span class="hl-var">$y</span><span class="hl-code">, </span><span class="hl-var">$textcolor</span><span class="hl-code">, </span><span class="hl-var">$fontfile</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></pre>
</div>
</div>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$img</span><span class="hl-code"> = </span><span class="hl-identifier">imagecreatefrompng</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">/home/john/Desktop/test.png</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$font_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$img</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$stroke_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$img</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">imagettfstroketext</span><span class="hl-brackets">(</span><span class="hl-var">$img</span><span class="hl-code">, </span><span class="hl-number">10</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">10</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-code">, </span><span class="hl-var">$font_color</span><span class="hl-code">, </span><span class="hl-var">$stroke_color</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">abstract.ttf</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">Hello, World!</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-number">2</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/&amp;title=Using+PHP+and+GD+to+add+border+to+text" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/&amp;title=Using+PHP+and+GD+to+add+border+to+text" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/&amp;title=Using+PHP+and+GD+to+add+border+to+text" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/&amp;title=Using+PHP+and+GD+to+add+border+to+text" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/&amp;submitHeadline=Using+PHP+and+GD+to+add+border+to+text&amp;submitSummary=%0D%0A%0D%0A&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/&amp;title=Using+PHP+and+GD+to+add+border+to+text" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Using+PHP+and+GD+to+add+border+to+text+-+http://www.johnciacia.com/449+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/using-php-and-gd-to-add-border-to-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic CAPTCHA</title>
		<link>http://www.johnciacia.com/2010/01/basic-captcha/</link>
		<comments>http://www.johnciacia.com/2010/01/basic-captcha/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 23:01:18 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[gd]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=443</guid>
		<description><![CDATA[Very basic code demonstrating the use of the GD library by creating a simple CAPTCHA.





		
			Submit this to Script &#38; Style
		
		
			Digg this!
		
		
			Share this on del.icio.us
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Buzz up!
		
		
			Share this on Reddit
		
		
			Share this on Technorati
		
		
			Tweet This!
		
		
			Subscribe to the comments for this post?
		





]]></description>
			<content:encoded><![CDATA[<p>Very basic code demonstrating the use of the GD library by creating a simple CAPTCHA.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">randomString</span><span class="hl-brackets">(</span><span class="hl-var">$length</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-var">$pattern</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-reserved">empty</span><span class="hl-brackets">(</span><span class="hl-var">$length</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-var">$length</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">10</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">

    </span><span class="hl-reserved">for</span><span class="hl-brackets">(</span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code">&lt;</span><span class="hl-var">$length</span><span class="hl-code">; </span><span class="hl-var">$i</span><span class="hl-code">++</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-var">$string</span><span class="hl-code"> .= </span><span class="hl-var">$pattern</span><span class="hl-brackets">{</span><span class="hl-identifier">rand</span><span class="hl-brackets">(</span><span class="hl-number">0</span><span class="hl-code">,</span><span class="hl-number">61</span><span class="hl-brackets">)</span><span class="hl-brackets">}</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">

    </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-var">$string</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">

</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">captcha</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-identifier">header</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Content-type: image/png</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$im</span><span class="hl-code"> = @</span><span class="hl-identifier">imagecreate</span><span class="hl-brackets">(</span><span class="hl-number">100</span><span class="hl-code">, </span><span class="hl-number">50</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">or</span><span class="hl-code"> </span><span class="hl-reserved">die</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Cannot Initialize new GD image stream</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$background_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$text_color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$string</span><span class="hl-code"> = </span><span class="hl-identifier">randomString</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagestring</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">10</span><span class="hl-code">, </span><span class="hl-number">5</span><span class="hl-code">, </span><span class="hl-number">5</span><span class="hl-code">,  </span><span class="hl-var">$string</span><span class="hl-code">, </span><span class="hl-var">$text_color</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagepng</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagedestroy</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">

</span><span class="hl-identifier">captcha</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/01/basic-captcha/&amp;title=Basic+CAPTCHA" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/01/basic-captcha/&amp;title=Basic+CAPTCHA" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/01/basic-captcha/&amp;title=Basic+CAPTCHA" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/01/basic-captcha/&amp;title=Basic+CAPTCHA" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/01/basic-captcha/&amp;submitHeadline=Basic+CAPTCHA&amp;submitSummary=Very%20basic%20code%20demonstrating%20the%20use%20of%20the%20GD%20library%20by%20creating%20a%20simple%20CAPTCHA.%0D%0A&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/01/basic-captcha/&amp;title=Basic+CAPTCHA" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/01/basic-captcha/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Basic+CAPTCHA+-+http://www.johnciacia.com/443+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/01/basic-captcha/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/basic-captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting to know GD</title>
		<link>http://www.johnciacia.com/2010/01/getting-to-know-gd/</link>
		<comments>http://www.johnciacia.com/2010/01/getting-to-know-gd/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 22:50:06 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=434</guid>
		<description><![CDATA[Create dynamic userbars with GD
Introduction:
Have you ever been on aim and received a message from one of your friends with a big long URL followed by something like &#8220;John%20Is%20Stupid.&#8221; You know what ever it is, wont be worth your time, but you click on it anyway to find someone goofy looking holding a sign and [...]]]></description>
			<content:encoded><![CDATA[<h2>Create dynamic userbars with GD</h2>
<p><strong>Introduction:</strong><br />
Have you ever been on aim and received a message from one of your friends with a big long URL followed by something like &#8220;John%20Is%20Stupid.&#8221; You know what ever it is, wont be worth your time, but you click on it anyway to find someone goofy looking holding a sign and on it printed in big bold letters &#8220;John Is Stupid.&#8221; Ever wonder how they work? Chances are, the script takes advantage of the GD functions. In this tutorial you will learn many GD functions that you can use to generate images. The goal for this tutorial is for you to generate a dynamic user bar.</p>
<p>Here is a list of the functions used in this tutorial:</p>
<ol>
<li><a href="http://us3.php.net/manual/en/function.header.php">header()</a></li>
<li><a href="http://us3.php.net/manual/en/function.imagecolorallocate.php">imagecolorallocate()</a></li>
<li><a href="http://us3.php.net/manual/en/function.imagettfbbox.php">imagettfbbox()</a></li>
<li><a href="http://us3.php.net/manual/en/function.imagesx.php">imagesx()</a></li>
<li><a href="http://us3.php.net/manual/en/function.abs.php">abs()</a></li>
<li><a href="http://us3.php.net/manual/en/function.imagettftext.php">imagettftext()</a></li>
<li><a href="http://us3.php.net/manual/en/function.imagepng.php">imagepng()</a></li>
<li><a href="http://us3.php.net/manual/en/function.imagedestroy.php">imagedestroy()</a></li>
</ol>
<p>The first thing you want to do is create the header type using the header function. Next you use the GD tools to create an image from a png file. In my case, I have userbar.png in the same directory as this script is in. The function imagecolorallocate creates a color using RGB (red-green-blue) format. The next three lines just set some basic information which isn’t that hard to understand. The last three lines to must of the work creating the image. The most important function here to pay attention to is imagettftext. The imagettftext requires 8 arguments which are the resource image, font size, the angle, x location, y location, font color, the actual font, and the string to be printed.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
    </span><span class="hl-identifier">header</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Content-type: image/png</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$im</span><span class="hl-code"> = </span><span class="hl-identifier">imagecreatefrompng</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">userbar.png</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$text</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">test</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
    </span><span class="hl-var">$font</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">font.ttf</span><span class="hl-quotes">'</span><span class="hl-code">;
    </span><span class="hl-var">$size</span><span class="hl-code"> = </span><span class="hl-number">8</span><span class="hl-code">;
    </span><span class="hl-identifier">imagettftext</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-var">$size</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">15</span><span class="hl-code">, </span><span class="hl-number">12</span><span class="hl-code">, </span><span class="hl-var">$color</span><span class="hl-code">, </span><span class="hl-var">$font</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagepng</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagedestroy</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>
<p>Now that we have GD generating an image, lets make it a little more complex. We&#8217;ve added the</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$text = $_GET['text'];</span></pre>
</div>
</div>
<p>line to allow the user to enter a random string, and we have also added the</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$size = imagettfbbox($fontsize, 0, $font, $text);
$dx = (imagesx($im)) - (abs($size[2]-$size[0])) - 20;</span></pre>
</div>
</div>
<p>Which calculate where to start printing the string on the image. The function imagettfbbox generates the length of the font string in pixels. If you were to use something like strlen($text) that would just return the number of characters in the string, which isn’t very usefull in this case. Next, we use the imagesx() function to determine the width of the image, we take that value and subtract the string length in pixels and subtract an extra 20 pixels to leave some room toward the end of the image.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
    </span><span class="hl-identifier">header</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Content-type: image/png</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$text</span><span class="hl-code"> = </span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">text</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code">;
    </span><span class="hl-var">$im</span><span class="hl-code"> = </span><span class="hl-identifier">imagecreatefrompng</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">userbar.png</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$font</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">font.ttf</span><span class="hl-quotes">'</span><span class="hl-code">;
    </span><span class="hl-var">$fontsize</span><span class="hl-code"> = </span><span class="hl-number">6</span><span class="hl-code">;
    </span><span class="hl-var">$size</span><span class="hl-code"> = </span><span class="hl-identifier">imagettfbbox</span><span class="hl-brackets">(</span><span class="hl-var">$fontsize</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-var">$font</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">calculate the pixel of the string</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-var">$dx</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-identifier">imagesx</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> - </span><span class="hl-brackets">(</span><span class="hl-identifier">abs</span><span class="hl-brackets">(</span><span class="hl-var">$size</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code">-</span><span class="hl-var">$size</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> - </span><span class="hl-number">20</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">calculate the location to start the text</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">imagettftext</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-var">$fontsize</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-var">$dx</span><span class="hl-code">, </span><span class="hl-number">13</span><span class="hl-code">, </span><span class="hl-var">$color</span><span class="hl-code">, </span><span class="hl-var">$font</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagepng</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagedestroy</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>
<p>At this point you could call yourself done. However you could add some extra features such as make the font color vary with the user input. Adding a simple if statement will accomplish this.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
    </span><span class="hl-identifier">header</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Content-type: image/png</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-var">$text</span><span class="hl-code"> = </span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">text</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code">;

    </span><span class="hl-var">$im</span><span class="hl-code"> = </span><span class="hl-identifier">imagecreatefrompng</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">userbar.png</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;

    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-var">$text</span><span class="hl-code"> == </span><span class="hl-quotes">&quot;</span><span class="hl-string">ADMINISTRATOR</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment">if administrator</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-var">$color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">red</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-var">$text</span><span class="hl-code"> == </span><span class="hl-quotes">&quot;</span><span class="hl-string">MODERATOR</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment">if moderator</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-var">$color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">255</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">blue</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-var">$text</span><span class="hl-code"> == </span><span class="hl-quotes">&quot;</span><span class="hl-string">JUNKIE</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment">if junkie</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-var">$color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">black</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
    </span><span class="hl-reserved">else</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-comment">//</span><span class="hl-comment">something else...</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-var">$color</span><span class="hl-code"> = </span><span class="hl-identifier">imagecolorallocate</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-number">128</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">green</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">

    </span><span class="hl-var">$font</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">font.ttf</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">font file</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-var">$fontsize</span><span class="hl-code"> = </span><span class="hl-number">6</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">font size</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-var">$stringsize</span><span class="hl-code"> = </span><span class="hl-identifier">imagettfbbox</span><span class="hl-brackets">(</span><span class="hl-var">$fontsize</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-var">$font</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">calculate the pixel of the string</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-var">$dx</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-identifier">imagesx</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> - </span><span class="hl-brackets">(</span><span class="hl-identifier">abs</span><span class="hl-brackets">(</span><span class="hl-var">$stringsize</span><span class="hl-brackets">[</span><span class="hl-number">2</span><span class="hl-brackets">]</span><span class="hl-code">-</span><span class="hl-var">$stringsize</span><span class="hl-brackets">[</span><span class="hl-number">0</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code"> - </span><span class="hl-number">20</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment">calculate the location to start the text</span><span class="hl-comment"></span><span class="hl-code">
    </span><span class="hl-identifier">imagettftext</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-code">, </span><span class="hl-var">$fontsize</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code">, </span><span class="hl-var">$dx</span><span class="hl-code">, </span><span class="hl-number">13</span><span class="hl-code">, </span><span class="hl-var">$color</span><span class="hl-code">, </span><span class="hl-var">$font</span><span class="hl-code">, </span><span class="hl-var">$text</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagepng</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-identifier">imagedestroy</span><span class="hl-brackets">(</span><span class="hl-var">$im</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></pre>
</div>
</div>
<p>Finally you can save this script as generator.php and display it in forums by using the html tags.</p>
<div class="quote">&lt;img src=&quot;http://www.yourdomain.com/generator.php?text=JUNKIE&quot; /&gt;</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2010/01/getting-to-know-gd/&amp;title=Getting+to+know+GD" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2010/01/getting-to-know-gd/&amp;title=Getting+to+know+GD" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2010/01/getting-to-know-gd/&amp;title=Getting+to+know+GD" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2010/01/getting-to-know-gd/&amp;title=Getting+to+know+GD" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2010/01/getting-to-know-gd/&amp;submitHeadline=Getting+to+know+GD&amp;submitSummary=Create%20dynamic%20userbars%20with%20GD%0D%0A%0D%0AIntroduction%3A%0D%0AHave%20you%20ever%20been%20on%20aim%20and%20received%20a%20message%20from%20one%20of%20your%20friends%20with%20a%20big%20long%20URL%20followed%20by%20something%20like%20%22John%2520Is%2520Stupid.%22%20You%20know%20what%20ever%20it%20is%2C%20wont%20be%20worth%20your%20time%2C%20but%20you%20click%20on%20it%20anyway%20to%20find%20someone%20goofy%20looking&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2010/01/getting-to-know-gd/&amp;title=Getting+to+know+GD" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2010/01/getting-to-know-gd/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Getting+to+know+GD+-+http://www.johnciacia.com/434+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2010/01/getting-to-know-gd/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/getting-to-know-gd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LOL Monday &#8211; Videos</title>
		<link>http://www.johnciacia.com/2009/11/lol-monday-videos/</link>
		<comments>http://www.johnciacia.com/2009/11/lol-monday-videos/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 06:00:44 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Humor]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=369</guid>
		<description><![CDATA[I found this video hilarious. For those of you who are &#8220;slow,&#8221; it is how comment systems work on blogs.

See more funny videos and funny pictures at CollegeHumor.
I found this one just as funny, but for a different reason&#8230;

I&#8217;m just trying to figure out how a GUI interface can track an ip address &#8211; let [...]]]></description>
			<content:encoded><![CDATA[<p>I found this video hilarious. For those of you who are &#8220;slow,&#8221; it is how comment systems work on blogs.<br />
<object type="application/x-shockwave-flash" data="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1771556&#038;fullscreen=1" width="540" height="360" ><param name="allowfullscreen" value="true"/><param name="wmode" value="transparent"/><param name="allowScriptAccess" value="always"/><param name="movie" quality="best" value="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1771556&#038;fullscreen=1"/><embed src="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1771556&#038;fullscreen=1" type="application/x-shockwave-flash" wmode="transparent"  width="540" height="360"  allowScriptAccess="always"></embed></object>
<div style="padding:5px 0; text-align:center; width:640px;">See more <a href="http://www.collegehumor.com/videos">funny videos</a> and <a href="http://www.collegehumor.com/pictures">funny pictures</a> at <a href="http://www.collegehumor.com/">CollegeHumor</a>.</div>
<p>I found this one just as funny, but for a different reason&#8230;<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/ygB0ZviqXac&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ygB0ZviqXac&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>I&#8217;m just trying to figure out how a GUI interface can track an ip address &#8211; let alone something written in VB.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2009/11/lol-monday-videos/&amp;title=LOL+Monday+-+Videos" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2009/11/lol-monday-videos/&amp;title=LOL+Monday+-+Videos" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2009/11/lol-monday-videos/&amp;title=LOL+Monday+-+Videos" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2009/11/lol-monday-videos/&amp;title=LOL+Monday+-+Videos" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2009/11/lol-monday-videos/&amp;submitHeadline=LOL+Monday+-+Videos&amp;submitSummary=I%20found%20this%20video%20hilarious.%20For%20those%20of%20you%20who%20are%20%22slow%2C%22%20it%20is%20how%20comment%20systems%20work%20on%20blogs.%0D%0ASee%20more%20funny%20videos%20and%20funny%20pictures%20at%20CollegeHumor.%0D%0A%0D%0A%0D%0A%0D%0AI%20found%20this%20one%20just%20as%20funny%2C%20but%20for%20a%20different%20reason...%0D%0A%0D%0A%0D%0AI%27m%20just%20trying%20to%20figure%20out%20how%20a%20GUI%20interface%20can%20track%20an%20&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2009/11/lol-monday-videos/&amp;title=LOL+Monday+-+Videos" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2009/11/lol-monday-videos/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=LOL+Monday+-+Videos+-+http://www.johnciacia.com/369+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2009/11/lol-monday-videos/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/11/lol-monday-videos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SEF URLs with out mod_rewrite</title>
		<link>http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/</link>
		<comments>http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 21:51:56 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=420</guid>
		<description><![CDATA[If you have done any web development, passing requests becomes an integral part of your code. Whether it is a session id, data to validate, or a view file to load you will most definitely end up passing one request or another. While working on my framework (which uses the model-view-controller design pattern), I decided [...]]]></description>
			<content:encoded><![CDATA[<p>If you have done any web development, passing requests becomes an integral part of your code. Whether it is a session id, data to validate, or a view file to load you will most definitely end up passing one request or another. While working on my framework (which uses the model-view-controller design pattern), I decided to pass the controller, which the framework will load, through the URL. Since the controller&#8217;s primary purpose is to handle incoming http requests, I also passed a &#8220;view&#8221; parameter through the URL (which the controller will delegate accordingly). At this point, my URLs became unattractive index.php?module=Blog&#038;view=index, which in todays world, of Web 2.0 sex appeal and search engine optimization, is just unacceptable. To circumvent the unsightly link, many developers choose to use mod_rewrite and define expressions in a .htaccess file. This is a perfectly legitimate practice for those of you who have mod_rewrite enabled on their server (and actually understand the rules). As an alternative, PHP&#8217;s $_SERVER['REQUEST_URI'] provides a cleaver solution.</p>
<p>What does $_SERVER['REQUEST_URI'] provide us with? Essentially, everything after the domain name. So if our URL is http://www.example.com/index.php?module=Blog&#038;view=index, our URI is index.php?module=Blog&#038;view=index. Moreover, if our URL is http://www.example.com/index.php/Blog/index, our URI is index.php/Blog/index. Using this, we can simply manipulate the URI to process incoming requests. First, we want to explode the URI at the file name, in my case it is index.php.</p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$requests = explode(&quot;/index.php/&quot;, $_SERVER['REQUEST_URI']);</span></pre>
</div>
</div>
<p>$request is now an array whose first element is everything before and including index.php, and whose second element is everything after index.php. By manipulating $requests[1] we can use that data as our data. </p>
<div class="hl-container">
<div class="hl-main">
<pre><span class="hl-code">$requests = explode(&quot;/index.php/&quot;, $_SERVER['REQUEST_URI']);
$uri = explode('/', $requests[1]);</span></pre>
</div>
</div>
<p>The $uri array now contains all our disguised requests, which we can use in the same way as a $_GET request (with the exception of a sexier URL).</p>
<p>With three lines of code we have transformed a ugly looking URL  http://www.example.com/index.php?module=Blog&#038;view=index to http://www.example.com/index.php/Blog/index  (a URL the most avid Web 2.0 gurus would find acceptable).</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/&amp;title=SEF+URLs+with+out+mod_rewrite" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/&amp;title=SEF+URLs+with+out+mod_rewrite" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/&amp;title=SEF+URLs+with+out+mod_rewrite" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/&amp;title=SEF+URLs+with+out+mod_rewrite" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/&amp;submitHeadline=SEF+URLs+with+out+mod_rewrite&amp;submitSummary=If%20you%20have%20done%20any%20web%20development%2C%20passing%20requests%20becomes%20an%20integral%20part%20of%20your%20code.%20Whether%20it%20is%20a%20session%20id%2C%20data%20to%20validate%2C%20or%20a%20view%20file%20to%20load%20you%20will%20most%20definitely%20end%20up%20passing%20one%20request%20or%20another.%20While%20working%20on%20my%20framework%20%28which%20uses%20the%20model-view-controller%20desig&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/&amp;title=SEF+URLs+with+out+mod_rewrite" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=SEF+URLs+with+out+mod_rewrite+-+http://www.johnciacia.com/420+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/11/sef-urls-with-out-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Laplace Transform</title>
		<link>http://www.johnciacia.com/2009/11/the-laplace-transform/</link>
		<comments>http://www.johnciacia.com/2009/11/the-laplace-transform/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 23:41:54 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=379</guid>
		<description><![CDATA[Pierre-Simon De Laplace (23 March 1749 – 5 March 1827) was a French mathematician and astronomer. In 1796 he formulated a nebular hypothesis of cosmic origin and was one of the first scientists to postulate the existence of black holes. He later proposed a solution to irregularities in Newton&#8217;s calculations and presented them in a [...]]]></description>
			<content:encoded><![CDATA[<p>Pierre-Simon De Laplace (23 March 1749 – 5 March 1827) was a French mathematician and astronomer. In 1796 he formulated a nebular hypothesis of cosmic origin and was one of the first scientists to postulate the existence of black holes. He later proposed a solution to irregularities in Newton&#8217;s calculations and presented them in a work called Mécanique céleste. According to legend, when asked by Napoleon why God did not appear in his discussion, Laplace replied &#8220;I had no need of that hypothesis.&#8221; Among many discoveries, Laplace is most notable for the Laplace Transform which aids in solving differential equations by allowing for the transformation of an equation from the time domain to the frequency domain.</p>
<p>For a signal <em>x(t)</em>, its Laplace transform <em>X(s)</em> is defined by<br />
<img src="http://quicklatex.com/cache/ql_fa30b209e1f8cb845276479e6e5e5ff2.gif" alt="\mathrm{X(s)=}\int\limits_{-\infty}^{\infty}\mathrm{x(t)}e^{-st}dt" title="\mathrm{X(s)=}\int\limits_{-\infty}^{\infty}\mathrm{x(t)}e^{-st}dt" style="vertical-align: -17px; border: none;"/></p>
<p><strong>Example: </strong>For a signal <em>x(t) = e</em><sup>-at</sup><em>u(t)</em> find the Laplace transform <em>X(s)</em>.</p>
<p>By definition<br />
<img src="http://quicklatex.com/cache/ql_06efd2963836186206dc3a1f3cb1983e.gif" alt="\mathrm{X(s)=}\int\limits_{-\infty}^{\infty}e^{-at}u(t)e^{-st}dt" title="\mathrm{X(s)=}\int\limits_{-\infty}^{\infty}e^{-at}u(t)e^{-st}dt" style="vertical-align: -17px; border: none;"/></p>
<p>Since <em>u(t) = 0</em> for <em>t &lt; 0</em> and <em>u(t) = 1</em> for <em>t ≥ 0</em>,<br />
<img src="http://quicklatex.com/cache/ql_68b88184ef1d37e63862f3463cfeff16.gif" alt="\mathrm{X(s)=}\int\limits_{0}^{\infty}e^{-at}e^{-st}dt = \mathrm{X(s)=}\int\limits_{0}^{\infty}e^{-(s+a)t}dt = -\frac{1}{s+1}e^{-(s+a)t}\big|_{0}^{\infty}" title="\mathrm{X(s)=}\int\limits_{0}^{\infty}e^{-at}e^{-st}dt = \mathrm{X(s)=}\int\limits_{0}^{\infty}e^{-(s+a)t}dt = -\frac{1}{s+1}e^{-(s+a)t}\big|_{0}^{\infty}" style="vertical-align: -17px; border: none;"/></p>
<p>Thus we can conclude<br />
<img src="http://quicklatex.com/cache/ql_d36deaf6e4921579f9f8cea6d73c929a.gif" alt="\mathrm{X(s)=}\frac{1}{s + a} \mathrm{for Re(s + a) > 0}" title="\mathrm{X(s)=}\frac{1}{s + a} \mathrm{for Re(s + a) > 0}" style="vertical-align: -7px; border: none;"/></p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-scriptstyle">
			<a href="http://scriptandstyle.com/submit?url=http://www.johnciacia.com/2009/11/the-laplace-transform/&amp;title=The+Laplace+Transform" rel="nofollow" title="Submit this to Script &amp; Style">Submit this to Script &amp; Style</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.johnciacia.com/2009/11/the-laplace-transform/&amp;title=The+Laplace+Transform" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.johnciacia.com/2009/11/the-laplace-transform/&amp;title=The+Laplace+Transform" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.johnciacia.com/2009/11/the-laplace-transform/&amp;title=The+Laplace+Transform" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-yahoobuzz">
			<a href="http://buzz.yahoo.com/submit/?submitUrl=http://www.johnciacia.com/2009/11/the-laplace-transform/&amp;submitHeadline=The+Laplace+Transform&amp;submitSummary=Pierre-Simon%20De%20Laplace%20%2823%20March%201749%20%E2%80%93%205%20March%201827%29%20was%20a%20French%20mathematician%20and%20astronomer.%20In%201796%20he%20formulated%20a%20nebular%20hypothesis%20of%20cosmic%20origin%20and%20was%20one%20of%20the%20first%20scientists%20to%20postulate%20the%20existence%20of%20black%20holes.%20He%20later%20proposed%20a%20solution%20to%20irregularities%20in%20Newton%27s%20ca&amp;submitCategory=science&amp;submitAssetType=text" rel="nofollow" title="Buzz up!">Buzz up!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.johnciacia.com/2009/11/the-laplace-transform/&amp;title=The+Laplace+Transform" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.johnciacia.com/2009/11/the-laplace-transform/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=The+Laplace+Transform+-+http://www.johnciacia.com/379+(via+@johnciacia)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://www.johnciacia.com/2009/11/the-laplace-transform/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2009/11/the-laplace-transform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
