<?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>ChristianSouth.com</title>
	<atom:link href="http://www.christiansouth.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christiansouth.com</link>
	<description>Musings of a coder</description>
	<lastBuildDate>Fri, 24 Jun 2011 22:30:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Parsing Google Fast Flip</title>
		<link>http://www.christiansouth.com/php/parsing-google-fast-flip/</link>
		<comments>http://www.christiansouth.com/php/parsing-google-fast-flip/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 04:00:08 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Fast Flip]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.christiansouth.com/?p=107</guid>
		<description><![CDATA[Introduction From time to time I spend a little too long on a project I probably shouldn&#8217;t. A while back I set out to pull in Google News Fast Flip data for my personal Homepage(you&#8217;ll see several projects from this). For those who are not famiiar with Google Fast Flip, it is a service that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>From time to time I spend a little too long on a project I probably shouldn&#8217;t. A while back I set out to pull in Google News Fast Flip data for my personal Homepage(you&#8217;ll see several projects from this). For those who are not famiiar with Google Fast Flip, it is a service that shows screenshots of news articles from several different sources. Now, unusual for Google there isn&#8217;t an API for Fast Flip. This would seem to be the end of the story, but if you pay attention to their page you will notice that they pull in the articles via AJAX. So I started with this to try to pull in data. The base URL is <a href="http://fastflip.googlelabs.com/data">http://fastflip.googlelabs.com/data</a>. If you open this URL up you will get nothing. This is because it requires that you to post data to it with a query string, a start, and a number of posts to pull. So lets curl that.</p>
<p><strong>The fun part</strong></p>
<p>Before we start here is a quick example of what you can do with the data: <a title="FastFlip Demo" href="http://www.christiansouth.com/fastflip/" target="_blank" style="font-weight: bold; color: #00F">Demo</a></p>
<pre class="brush: php; title: ; notranslate">

&lt;?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://fastflip.googlelabs.com/data');
curl_setopt($ch, CURLOPT_POSTFIELDS, &quot;q=section:\&quot;Sci/Tech\&quot;&amp;start=0&amp;num=1&quot;);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);

echo $content;
</pre>
<p>This will get you what looks like JSON data but will not parse with json_decode(). It looks something like this:</p>
<pre class="brush: plain; title: ; notranslate">

[['06/21/11 00:00','The Atlantic','Forget the Specs, Is the New MacBook Air Going to Be Black?','http://www.theatlantic.com/technology/archive/2011/06/forget\x2Dthe\x2Dspecs\x2Dis\x2Dthe\x2Dnew\x2Dmacbook\x2Dair\x2Dgoing\x2Dto\x2Dbe\x2Dblack/240760/','rLgszGxdkW19xM','Nicholas Jackson','Sci/Tech','','640 956','992 956','http://g1.gstatic.com/news/screenshots/u2yJ66dzwq5X2M\x2Dtiny.png','http://g1.gstatic.com/news/screenshots/u2yJ66dzwq5X2M\x2Dmed.png','http://g3.gstatic.com/news/screenshots/u2yJ66dzwq5X2M.png','1','Nicholas Jackson \x2D Nicholas Jackson is an associate editor at The Atlantic. A former media aggregator for Slate, his writing has also appeared in Encyclopaedia ...','http://www.theatlantic.com/technology/archive/2011/06/forget\x2Dthe\x2Dspecs\x2Dis\x2Dthe\x2Dnew\x2Dmacbook\x2Dair\x2Dgoing\x2Dto\x2Dbe\x2Dblack/240760/','1','3','8797714876515','','','0','']]
</pre>
<p>On this one I wasn&#8217;t quite sure so I have this custom parser (thanks to Matt for the help with the regex):</p>
<pre class="brush: php; title: ; notranslate">

$page = array_map(function ($n) {
return preg_replace(&quot;#^\\[*'?(.*)'?\\]*$#&quot;, '$1', preg_split(&quot;#','#&quot;, $n));
}, preg_split('#\],#', $content));
</pre>
<p><span style="font-size: 14px; color: #f00; font-weight: bold;">Update:</span><br />
Thanks to <a href="http://www.reddit.com/user/adbe">adbe</a> on reddit, I was able to simplify this a bit with the following chunk of code:</p>
<pre class="brush: php; title: ; notranslate">
$search = array('\'', '\\');
$replacement = array('&quot;', '\\\\');
$content = str_replace($search, $replacement, $content);
</pre>
<p>From here you can actually json_decode() the content variable which will give you an array.</p>
<p>What you get from this is an array of 0-22. For me this was the most difficult part. I let this run as a cron for a few days and just dumped everything to a table. To save you a LOT of trouble this is what I found (and didn&#8217;t)<br />
<span style="font-size: 14px; color: #f00; font-weight: bold;">Update:</span><br />
Thanks to one of the Google devs for confirming the fields I didn&#8217;t know. </p>
<p>0 &#8211; Date Time the article was written<br />
1 &#8211; The news source<br />
2 &#8211; Article Title<br />
3 &#8211; Link to the article<br />
4 &#8211; What I think is a Google internal id (As per the Google dev this is an internal id)<br />
5 &#8211; Author of the article<br />
6 &#8211; Category the post is in (Check below for a full list)<br />
7 &#8211; This field is always blank(As per the Google dev this isn&#8217;t used)<br />
8 &#8211; Medium image dimensions<br />
9 &#8211; Large image dimension<br />
10 &#8211; Thumbnail image URL<br />
11 &#8211; Medium image URL<br />
12 &#8211; Large image URL<br />
13 &#8211; Always 1 or 0 but I don&#8217;t know what it represents (as per the Google dev this is for showing ads)<br />
14 &#8211; A snippet of the content<br />
15 &#8211; A link to the article, always exactly the same as number 2<br />
16 &#8211; Always 1, but again I don&#8217;t know what this field represents<br />
17 &#8211; Always 1 or 0 but I don&#8217;t know what it represents(As per the Google dev this is actually the number of likes but might not be used anymore)<br />
18 &#8211; A number but I don&#8217;t know what it represents<br />
19 &#8211; Always blank<br />
20 &#8211; Topics or Tags<br />
21 &#8211; A number but I don&#8217;t know what it represents (As per the Google dev this is a personalization score)<br />
22 &#8211;  Whether the source is Tribune Company, Wenner Media, or its blank</p>
<p>As you can tell I have a few holes in this I would love to fill in. If you can help with this I would be glad to hear what they are. As far as the sections I use the following array:</p>
<pre class="brush: php; title: ; notranslate">

$sections = array(
'Politics',
'Business',
'U.S.',
'World',
'Sports',
'Sci/Tech',
'Entertainment',
'Health',
'Opinion',
'Travel',
'Environment'
);
</pre>
<p><strong>Conclusion</strong></p>
<p>Now, this is of course just the starter. I actually loop through all of the sections and store the information I want to my HUD database. What I can tell you from the time I&#8217;ve had this running is Google seems to store the images for about a month and then they remove them. I hope this helps someone with a project they are working on and as always I&#8217;m interested in your thoughts and how you think this could be used.</p>
<p><span style="color: red">It has been pointed out, and I agree, that this should not be used for any sort of production application. When I said that I hoped it helped someone with a project I meant a personal project. I just wanted to clear this up.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/parsing-google-fast-flip/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using ZF Tool to Create a Modular Zend Framework Application</title>
		<link>http://www.christiansouth.com/php/using-zf-tool-to-create-a-modular-application/</link>
		<comments>http://www.christiansouth.com/php/using-zf-tool-to-create-a-modular-application/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 18:28:16 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.christiansouth.com/?p=90</guid>
		<description><![CDATA[Introduction This is just a quick guide on creating a modular application structure in the Zend Framework using the Zend Framework Tool (more or less). The Process First move to your directory. Now create the project Now that we have a functioning app. The next step is to turn it into a modular application. First [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>This is just a quick guide on creating a modular application structure in the Zend Framework using the Zend Framework Tool (more or less).</p>
<p><strong>The Process</strong></p>
<p>First move to your directory.</p>
<pre class="brush: plain; title: ; notranslate">
cd /var/www/
</pre>
<p>Now create the project</p>
<pre class="brush: plain; title: ; notranslate">
zf create project MyApp
cd MyApp
</pre>
<p>Now that we have a functioning app. The next step is to turn it into a modular application. First we remove the controller and view directories then we create our first module with its controller, action, and view.</p>
<pre class="brush: plain; title: ; notranslate">
rm -rf application/controllers/
rm -rf application/views/
rm -rf application/models/
zf create module default
zf create controller Index 1 default
</pre>
<p>Now that we have our default controller with a index controller and index view, were almost there. The system isnâ€™t yet setup to use the modules so the last thing we need to do is edit the application configuration file. In the application config you will make the following change</p>
<pre class="brush: plain; title: ; notranslate">
; Remove this line from your current application.ini
resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot;
; Add this line in its place
resources.frontController.moduleDirectory = APPLICATION_PATH &quot;/modules&quot;
</pre>
<p><strong>Conclusion</strong></p>
<p>This is the process that I currently use. I&#8217;m sure there is a much easier solution to this but I haven&#8217;t found it. Please let me know in comments if you know of a better way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/using-zf-tool-to-create-a-modular-application/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PDO Getting Started Part 2 &#8211; PDOStatement</title>
		<link>http://www.christiansouth.com/php/pdo-getting-started-part-2-pdostatement/</link>
		<comments>http://www.christiansouth.com/php/pdo-getting-started-part-2-pdostatement/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 02:37:51 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[PDO]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=74</guid>
		<description><![CDATA[Introduction Most of your work with PDO will center around the PDOStatement class. Of all of the classes in the PDO package this is the one that you will need to know the best. As such I will try to cover the core functions with a little more code then last time. I will not [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>Most of your work with PDO will center around the PDOStatement class. Of all of the classes in the PDO package this is the one that you will need to know the best. As such I will try to cover the core functions with a little more code then last time. I will not be covering all of the functions in the post as there isn&#8217;t much I will be able to expand upon from the PHP docs. My goal is to give you a mid level understanding of the methods and how/when to use them so learning the rest of the methods will be a lot easier for you. For this post I will be writing examples that center around pulling user data for an admin panel like section of a site.</p>
<p><span id="more-74"></span></p>
<p><strong>PDOStatement::execute()</strong></p>
<p>The execute method does exactly what it sounds like. It runs the query for its statement. Optionally when escaping parameters while using question marks you will pass them into execute as an array in the order they will be replaced in the query. Lets get right into the example with this one. First we will generate the statement object.</p>
<pre class="brush: php; title: ; notranslate">

$stmt = $db-&gt;prepare('SELECT u.username, u.display_name FROM users u WHERE u.id = ?');
</pre>
<p>Notice the question mark? This is where PDOStatement will replace the value we tell it to run. By giving the value to PDO, we let PDO escape the value which helps to protect you against SQL injections. To tell PDOStatement which value to put in there we pass it in as an array to the execute function:</p>
<pre class="brush: php; title: ; notranslate">
$userId = 10;
$stmt-&gt;execute(array($userId)); // runs - SELECT u.username, u.display_name FROM USERS u where u.id = 10;
</pre>
<p>If you don&#8217;t have any values to escape you just wouldn&#8217;t pass in the array parameter. It should also be noted that the return value of execute is a bool. TRUE if the query was successful FALSE if it wasn&#8217;t. The stumble here is it will ONLY return FALSE if the SQL has an error. So if the SQL is valid but return no rowset you will still get a TRUE return value. Keep this in mind when checking the return value.</p>
<p><strong>rowCount</strong></p>
<p>Row count will give you either the number of affected rows, or the number of returned rows depending on your query (Please note that in some systems it will only return affected rows when running DELETE, INSERT, and UPDATE queries. In MySQL running PHP 5.3 it will return the number or returned rows. Just keep in mind YMMV).</p>
<pre class="brush: php; title: ; notranslate">
$stmt = $db-&gt;prepare('SELECT * FROM users WHERE role_id = 1'); // select all admins
$stmt-&gt;execute();
echo $stmt-&gt;rowCount(); // Echo the number of admins in the database
$stmt = $db-&gt;prepare('DELETE FROM users WHERE id = 10');
$stmt-&gt;execute();
echo $stmt-&gt;rowCount(); // Assuming there is a user with the ID of 10 this will echo 1
</pre>
<p><strong>Binding input</strong></p>
<p>Binding provides a way to assign values that need to be escaped and inserted into a SQL statement(Like the first question mark example we looked at). When using the methods bindParam or bindValue it expects named place holders. This can make larger queries easier to read. The only difference between bindParam and bindValue is bindParam passes the value you assign by reference and bindValue is not. This works well when you have stored procedures that have input/output values, but this is a topic for later. Lets convert the above example to use named place holders.</p>
<pre class="brush: php; title: ; notranslate">
$stmt = $db-&gt;prepare('SELECT u.username, u.display_name FROM users u WHERE u.id = :userId');
$stmt-&gt;bindValue(':userId', 10);
$stmt-&gt;execute(); // Runs the same query as above.
</pre>
<p>Note that if you convert the above example to use bindParam it will throw a warning because you cannot pass a value by reference. Just keep this stumbling block in mind when writing your queries</p>
<p><strong>Fetching data</strong></p>
<p>So after all that lets finally get our data! PDOStatement provides a few different ways to fetch the data from your query. We will cover them one at a time</p>
<p><strong>fetch</strong></p>
<p>I think its fairly obvious just from the name what this does, so I wont say to much about it. I will note that once you use this function it moves on to the next result in the row set. If there isn&#8217;t another row it will return FALSE.</p>
<pre class="brush: php; title: ; notranslate">
$stmt = $db-&gt;prepare('SELECT * FROM users WHERE role_id = 1'); // select all admins
$stmt-&gt;execute();

while($row = $stmt-&gt;fetch()) {
    echo $row['username'].'
'; // Just echo out the username in a list
}
</pre>
<p>The fetch method takes a few params but I will only cover the first. This param tells the method in what way to return the row values. By default it returns an array that includes numbered keys as well as keys with column names. In most cases you will use one or the other but not both. Lets look at some examples:</p>
<pre class="brush: php; title: ; notranslate">
// ... build and execute statement
while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
    // This one will work exactly as above the returns row just will not have numbered keys
    echo $row['username'].'
'; // Just echo out the username in a list
}

// Option 2: fetch stdClass
while($row = $stmt-&gt;fetch(PDO::FETCH_OBJ)) {
    echo $row-&gt;username .'
';
}

// Option 3: this is the same as option 2 just using a built in PDOStatement method
while($row = $stmt-&gt;fetchObject()) {
    echo $row-&gt;username .'
';
}
</pre>
<p>PDOStatement has some other options for fetching types that we will cover in a little more advanced post.</p>
<p><strong>Fetching EVERYTHING</strong></p>
<p>The final option is to pull all the rows at once in an array. You do this through the fetchAll method. Again you can tell this method how to return the rows.</p>
<pre class="brush: php; title: ; notranslate">
// ... build and execute statement
$rowSet = $stmt-&gt;fetchAll(); // This will give you an array of arrays
$rowSet = $stmt-&gt;fetchAll(PDO::FETCH_OBJ); // This will give you an array of stdClasses
</pre>
<p><strong>Conculsion</strong></p>
<p>I think we have covered quite a bit for this post and this is a good place to stop. The sad part is there is still quite a bit with building and executing queries to cover. I just don&#8217;t think its smart to try to do it all in one post. Feel free to ask questions about the topics I covered here. Also let me know if you think I should have covered anything that I didn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/pdo-getting-started-part-2-pdostatement/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PDO Getting Started</title>
		<link>http://www.christiansouth.com/php/pdo-getting-started/</link>
		<comments>http://www.christiansouth.com/php/pdo-getting-started/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 01:17:52 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[PDO]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=63</guid>
		<description><![CDATA[Part 2 of this post is now out. It covers PDOStatement. Check it out here! Introduction Through my time in development, I&#8217;ve used several database solutions, but to be honest the easiest solution for me has always been PDO. It provides powerful solutions while not getting in your way. On top of this it doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<div style="margin: 0 auto; text-align: center; font-size: 16px; font-weight: bold; color: #f00;">Part 2 of this post is now out. It covers PDOStatement. Check it out <a href="http://christiansouth.com/2011/04/pdo-getting-started-part-2-pdostatement/">here!</a></div>
<p><strong>Introduction</strong></p>
<p>Through my time in development, I&#8217;ve used several database solutions, but to be honest the easiest solution for me has always been PDO. It provides powerful solutions while not getting in your way. On top of this it doesn&#8217;t have the large learning curve that comes with many of the other full blown solutions.</p>
<p>In this post we will cover the extreme basics of using PDO. We will be covering the database object itself from connecting to the different ways to run queries. In future posts we will cover the other topics we don&#8217;t have room for in this post.</p>
<p><span id="more-63"></span><br />
<strong>DSN</strong></p>
<p>The first part to connecting to your database instance is a <abbr title="Data Source Name">DSN</abbr>. This is the connection string that will tell PDO to connect to your database. Your <abbr title="Data Source Name">DSN</abbr> will change depending on the type of database you are connecting to but in this post I will be giving MySQL examples. Your DSN will include at minimum type, host, and database name.</p>
<pre class="brush: php; title: ; notranslate">
// Basic MySQL DSN
$dsn = 'mysql:host=localhost;dbname=test';
</pre>
<p>This will connect to localhost and the test database. The last option (should you need it) is the port number:</p>
<pre class="brush: php; title: ; notranslate">
// Basic MySQL DSN
$dsn = 'mysql:host=localhost;dbname=test;port=3306';
</pre>
<p>Now lets connect to the database. When constructing the PDO class you pass in the DSN we just built, along with a username and password. Optionally the constructor takes a file parameter include driver options. This a little more of an advanced topic we will cover later. For now lets just work on connecting to the database:</p>
<pre class="brush: php; title: ; notranslate">
// Define DSN, username and password
$dsn          = 'mysql:host=localhost;dbname=test';
$username = 'testingUser';
$password  = 'testingPass';

// We try catch to stop app failures
try {
    $db = new PDO($dsn, $username, $password);
} catch(PDOException $e) {
    /**
     * Handle exception here
     */
}
</pre>
<p>This is a simple example on creating a database connection, but in most cases this will be enough for your project. Lets move on to actually working with the database.</p>
<p><strong>Querying the database</strong></p>
<p>For querying the database you have 3 options that we will cover 1 at a time.</p>
<p><strong>PDO::exec()</strong></p>
<p>The exec function is used exclusively for database calls that don&#8217;t have a result row set. This would include inserts, creating or modifying tables, and procedure calls that don&#8217;t have row sets. As a side note you shouldn&#8217;t use exec if you have data that needs to be sanitized (Solutions for this will be covered in a bit). Lets look at a simple example:</p>
<pre class="brush: php; title: ; notranslate">
// ... Code from above for connecting to the database
$password = hash('sha512', 'superAdminPassword');
$rowCount = $db-&gt;exec(&quot;INSERT INTO users(username, password) VALUES('admin', '$password')&quot;);
echo &quot;Inserted $rowCount rows&quot;;
</pre>
<p>Again this is a simple example but it covers most use cases. Just remember this function shouldn&#8217;t be used for data that needs sanitized.</p>
<p><strong>PDO::query()</strong></p>
<p>PDO::query allows you to run a query against the database that returns a row set. I will note here that I prefer to use the prepare function that is covered later. As with exec this function shouldn&#8217;t be used if you have user data to escape. The query function works pretty much like the exec function with exception of the return value. With the query method you will get a PDOStatement return value with your data in it, or a false return value on a failed query(Either no result set or SQL error). Lets look at a simple example:</p>
<pre class="brush: php; title: ; notranslate">
$result = $db-&gt;query('SELECT username FROM users');
foreach($result as $row) {
    echo $row['username'].'&lt;br /&gt;'; // Output all usernames from the database.
}
</pre>
<p><strong>PDO::prepare()</strong></p>
<p>&nbsp;</p>
<p>I saved this method for last because it deserves (and will probably get) its own post. You will more then likely use this post more then any other one. This is the function that will allow you to escape user data and store a query to run multiple times. Again for this post we are going to cover a very simple example and cover the functionality of PDOStatements further in a future post. Lets look at inserting multiple users:</p>
<pre class="brush: php; title: ; notranslate">
$stmt = $db-&gt;prepare('INSERT INTO users(username, password) VALUES(?, ?)');
$users = array(
    'testUser1' =&gt; hash('sha512', 'password1'),
    'testUser2' =&gt; hash('sha512', 'password2')
);

foreach($users as $username =&gt; $password) {
    $stmt-&gt;execute(array($username, $password));
}
</pre>
<p><strong>Conclusion</strong></p>
<p>&nbsp;</p>
<p>This concludes the basic functionality you get from PDO. I hope it gives you enough of a grasp of the class to get you started. Check back for more advanced usage of the classes that surround PDO. As always if you have questions or comments I would love to hear them</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/pdo-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Prototyping part 2</title>
		<link>http://www.christiansouth.com/php/php-prototyping-part-2/</link>
		<comments>http://www.christiansouth.com/php/php-prototyping-part-2/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 17:24:59 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=54</guid>
		<description><![CDATA[I had quite a bit of fun working on the prototyping class but I&#8217;ve realized I&#8217;ve missed a lot of things. So I sat down today to expand it a bit. I added in accessing of parent class variables (Don&#8217;t know how I missed this one). I also added in the ability to assign a [...]]]></description>
			<content:encoded><![CDATA[<p>I had quite a bit of fun working on the prototyping class but I&#8217;ve realized I&#8217;ve missed a lot of things. So I sat down today to expand it a bit. I added in accessing of parent class variables (Don&#8217;t know how I missed this one). I also added in the ability to assign a function to a variable to call it later. Lets look at some examples:</p>
<p><strong>First I added JavaScript like loading of the functions, this</strong></p>
<pre class="brush: php; title: ; notranslate">
$test1 = new Prototype('DateTime');
$test1-&gt;setDate = function() use($test1) {
    $args = func_get_args();
    $args[0]++;
    $test1-&gt;parentCall('setDate', $args);
};
</pre>
<p><strong>Now we assign it to a variable:</strong></p>
<pre class="brush: php; title: ; notranslate">
$func = $test1-&gt;setDate;
$func(2011, 4, 21);
echo $test1-&gt;format('Y-m-d'); // 2012-04-21 since our expansion increments the year

// But it still works from the object itself
$test1-&gt;setDate(2021, 4, 21);
echo $test1-&gt;format('Y-m-d'); // 2022-04-21
</pre>
<p><strong>Finally assigning non-extended functions to variables</strong></p>
<pre class="brush: php; title: ; notranslate">
$func2 = $test1-&gt;format;
echo $func2('Y-m-d'); // 2022-04-21
</pre>
<p>So I think the class is really shaping up. It still needs work and I&#8217;m still interested in your ideas, so feel free to let me know.</p>
<p><strong><a href="https://bitbucket.org/csouth/christians-blog/src/tip/phpPrototyping/Prototype.php">Here is the class itself now on BitBucket</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/php-prototyping-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Prototyping</title>
		<link>http://www.christiansouth.com/php/php-prototyping/</link>
		<comments>http://www.christiansouth.com/php/php-prototyping/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 01:30:36 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Prototyping]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=45</guid>
		<description><![CDATA[This has now been updated! Please check out the new post! So its been a while. Change of job, new babies, and other random events have filled my time. I think I&#8217;m ready to start blogging again and I&#8217;m hoping that this one really interests everyone. The one thing I like the most about JavaScript [...]]]></description>
			<content:encoded><![CDATA[<div style="margin: 0 auto; text-align: center; font-size: 16px; font-weight: bold; color: #f00;">This has now been updated! Please check out the new <a href="http://christiansouth.com/2011/04/php-prototyping-part-2/">post!</a></div>
<p>So its been a while. Change of job, new babies, and other random events have filled my time. I think I&#8217;m ready to start blogging again and I&#8217;m hoping that this one really interests everyone.</p>
<p>The one thing I like the most about JavaScript is prototyping. It kind of annoys me that PHP doesn&#8217;t have this function, but there isn&#8217;t really anything we (non-core developers) can do about that. I have come up with a class that allows for a SEMI prototyping solution. Now I have seen elsewhere that people have put together a class that will let you add closures and use them as functions but this isn&#8217;t really prototyping as you cannot modify existing class methods. So this solution is something that I whipped up in about 30 minutes, and I&#8217;m very interested in people tweaks, and suggestions. Here&#8217;s how it works&#8230;</p>
<p>Basic loading for building a class on the fly</p>
<pre class="brush: php; title: ; notranslate">

$test1 = new Prototype();
$test1-&gt;prototype('testingFunction', function() use($test1){
    echo 'Hi!';
});
$test1-&gt;testingFunction(); // Echos Hi!
</pre>
<p>Now lets actually extend a class that exists. Here we will extend a method of the class but then call it right after our extension.</p>
<pre class="brush: php; title: ; notranslate">

$test2 = new Prototype('DateTime');
$test2-&gt;prototype('setDate', function() use($test2) {
    echo 'Hi!2';
    $test2-&gt;parentCall('setDate', func_get_args());
});
</pre>
<p>simple right?</p>
<p>&nbsp;</p>
<p>Okay enough examples&#8230; Here is the class itself.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * Mock prototyping setup for PHP
 *
 * @author    Christian South [christian (at) nopantssoftware (dot) com]
 * @category  Prototype
 * @license   New BSD License
 * @copyright Copyright (c) 2011 No Pants Software
 */
class Prototype
{
    /**
     * Extended Class
     * @var mixed
     */
    protected $_extendedClass;

    /**
     * Extension methods
     * @var array
     */
    protected $_extensions = array();

    /**
     * Call function
     *
     * @param string $functionName
     * @param array $args
     * @return mixed
     */
    public function __call($functionName, $args)
    {
        if(isset($this-&gt;_extensions[$functionName])) {
            return call_user_func_array($this-&gt;_extensions[$functionName], $args);
        } elseif(method_exists($this-&gt;_extendedClass, $functionName)) {
            return call_user_func_array(array($this-&gt;_extendedClass, $functionName), $args);
        }

        throw new Exception('Unable to find method: '.$functionName);
    }

    /**
     * Class Constructor
     *
     * @param mixed $className
     * @return void
     */
    public function __construct($className = null)
    {
        if(null !== $className) {
            if(is_string($className)) {
                $this-&gt;_extendedClass = new $className();
            } else {
                $this-&gt;_extendedClass = $className;
            }
        }
    }

    /**
     * Call a parent function
     *
     * @param string $functionName
     * @return mixed
     */
    public function parentCall($functionName)
    {
        $args = func_get_args();
        array_shift($args);
        return call_user_func_array(array($this-&gt;_extendedClass, $functionName), $args[0]);
    }

    /**
     * Add extension Method
     *
     * @param string $functionName
     * @param Closure $function
     * @return Prototype
     */
    public function prototype($functionName, Closure $function)
    {
        $this-&gt;_extensions[$functionName] = $function;
        return $this;
    }
}
</pre>
<p>Again, I&#8217;m interested in every ones thoughts on tweaks and expansions on this. And even things that you see wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/php-prototyping/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Benchmarking Redux</title>
		<link>http://www.christiansouth.com/php/php-benchmarking-redux/</link>
		<comments>http://www.christiansouth.com/php/php-benchmarking-redux/#comments</comments>
		<pubDate>Wed, 19 May 2010 00:08:03 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[iMorf]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=40</guid>
		<description><![CDATA[So after the comment from Jay in regards to my previous post about PHP benchmarking I decided to sit down and write a PHP class for my upcoming framework that handles benchmarking. Usage is is fairly simple and is as follows: Its a fairly simple class but provides for tracking different elements of your application [...]]]></description>
			<content:encoded><![CDATA[<p>So after the comment from Jay in regards to my previous post about PHP benchmarking I decided to sit down and write a PHP class for my upcoming framework that handles benchmarking.</p>
<p>Usage is is fairly simple and is as follows:</p>
<pre class="brush: php; title: ; notranslate">
$benchmark = \IMorf\Benchmark::getInstance();
$benchmark-&gt;startTimer('fullLoad');
$benchmark-&gt;startMemoryTracker('fullLoad');
/**
 * Lots and Lots of code here
 */
$benchmark-&gt;startTime('someOtherTime');
/**
 * More code
 * and at the end or wherever you want to echo
 */
echo $benchmark-&gt;getTimer('someOtherTime');
echo $benchmark-&gt;getTimer('fullLoad');
echo $benchmark-&gt;getMemoryTracker('fullLoad');
</pre>
<p>Its a fairly simple class but provides for tracking different elements of your application on the fly. Here&#8217;s the code I will be using. If you have any questions let me know.</p>
<p><span id="more-40"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * iMorf PHP Framework - Morphing PHP one line at a time
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled with
 * this package in the file LICENSE.txt. It is also available through the
 * world-wide-web at this URL:
 * {@link http://www.imorf.com/license/new-bsd}
 * If you did not receive a copy of the license and are unable to obtain
 * it through our website, please send an email to license@imorf.com
 * so we can send you a copy immediately.
 *
 * @category   iMorf
 * @package    Benchmark
 * @copyright  Copyright (c) 2010 Xistins Technologies {@link http://www.xistins.com}
 * @author     Christian South [csouth (at) xistins (dot) com] {@link http://www.christiansouth.com}
 * @version    v0.0.1d
 */
namespace IMorf;

/**
 * Base Benchmark
 * Inspiration from Jay Gilford {@link http://www.jaygilford.com/php/simple-timer-class-for-benchmarking/}
 *
 * @category   iMorf
 * @package    Benchmark
 * @copyright  Copyright (c) 2010 Xistins Technologies {@link http://www.xistins.com}
 * @author     Christian South [csouth (at) xistins (dot) com] {@link http://www.christiansouth.com}
 * @version    v0.0.1d
 */
class Benchmark
{
    /**
     * Singleton Instance
     * @var iMorf\Benchmark
     */
    protected static $_instance = null;

    /**
     * All application timers
     * @var array
     */
    protected $_timers = array();

    /**
     * All application memory trackers
     * @var array
     */
    protected $_memoryTrackers = array();

    /**
     * All times left
     * @var array
     */
    protected $_times = array();

    /**
     * All application memory trackers
     * @var array
     */
    protected $_memory = array();

    /**
     * Return all memory trackers
     *
     * @return array
     */
    public function getAllMemoryTrackers()
    {
        foreach($this-&gt;_memoryTrackers as $memoryName =&gt; $memory) {
            $this-&gt;stopMemoryTracker($memoryName);
        }

        return $this-&gt;_memory;
    }

    /**
     * Return all times
     *
     * @return array
     */
    public function getAllTimes()
    {
        foreach($this-&gt;_timers as $timerName =&gt; $time) {
            $this-&gt;stopTimer($timerName);
        }

        return $this-&gt;_times;
    }

    /**
     * Singleton Instance
     *
     * @return iMorf\Benchmark
     */
    public static function getInstance()
    {
        if(null === self::$_instance) {
            self::$_instance = new self;
        }

        return self::$_instance;
    }

    /**
     * Get Memory Tracker
     *
     * @param  string $name Unique memory tacker name
     * @return float
     */
    public function getMemoryTracker($name, $decimals = 2)
    {
        if(isset($this-&gt;_memoryTrackers[$name])) {
            $this-&gt;stopMemoryTracker($name);
        }

        if(!isset($this-&gt;_memory[$name])) {
            throw new Exception(&quot;Unable to get memory tracker by the name of $name&quot;);
        }

        return number_format(($this-&gt;_memory[$name]/1000), $decimals);
    }

    /**
     * Get a time
     *
     * @param  string $name Unique timer name
     * @return float
     */
    public function getTimer($name, $decimals = 3)
    {
        /**
         * Stop Timer if its started
         */
        if(isset($this-&gt;_timers[$name])) {
            $this-&gt;stopTimer($name);
        }

        if(!isset($this-&gt;_times[$name])) {
            throw new Exception(&quot;Unable to get time for timer by the name of $name&quot;);
        }

        return number_format($this-&gt;_times[$name], $decimals);
    }

    /**
     * Start Memory Tracker
     *
     * @param  string $name Unique memory tracker name
     * @return iMorf\Benchmark
     */
    public function startMemoryTracker($name)
    {
        if(isset($this-&gt;_memoryTrackers[$name]) || isset($this-&gt;_memory[$name])) {
            throw new Exception(&quot;A memory tracker by the name of $name already exists&quot;);
        }

        $this-&gt;_memoryTrackers[$name] = memory_get_usage();
        return $this;
    }

    /**
     * Start Timer
     *
     * @param  string $name Unique timer name
     * @return iMorf\Benchmark
     */
    public function startTimer($name)
    {
        if(isset($this-&gt;_timers[$name]) || isset($this-&gt;_times[$name])) {
            throw new Exception(&quot;A timer by the name of $name already exists&quot;);
        }

        $this-&gt;_timers[$name] = microtime(true);
        return $this;
    }

    /**
     * Stop Memory Tracker
     *
     * @param  string $name Unique memory tracker name
     * @return iMorf\Benchmark
     */
    public function stopMemoryTracker($name)
    {
        if(!isset($this-&gt;_memoryTrackers[$name])) {
            throw new Exception(&quot;You don't have a memory tracker by the name of $name&quot;);
        }

        $memory = memory_get_usage();
        unset($this-&gt;_memoryTrackers[$name]);

        $this-&gt;_memory[$name] = $memory - memory_get_usage();
        return $this;
    }

    /**
     * Stop Timer
     *
     * @param  string $name Unique timer name
     * @return iMorf\Benchmark
     */
    public function stopTimer($name)
    {
        if(!isset($this-&gt;_timers[$name])) {
            throw new Exception(&quot;You don't have a timer by the name of $name&quot;);
        }

        $time = $this-&gt;_timers[$name];
        unset($this-&gt;_timers[$name]);

        $this-&gt;_times[$name] = microtime(true) - $time;
        return $this;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/php-benchmarking-redux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Benchmarking</title>
		<link>http://www.christiansouth.com/php/php-benchmarking/</link>
		<comments>http://www.christiansouth.com/php/php-benchmarking/#comments</comments>
		<pubDate>Fri, 14 May 2010 03:25:15 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmarking]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=25</guid>
		<description><![CDATA[The most common way to benchmark in PHP is by testing the time the script runs with something like In most cases this works. But I was looking to track a bit more then load time while testing my upcoming PHP 5.3 framework. So I created a little script that tracks load time, page your [...]]]></description>
			<content:encoded><![CDATA[<p>The most common way to benchmark in PHP is by testing the time the script runs with something like</p>
<pre class="brush: php; title: ; notranslate">
$startTime = microtime(TRUE);
// Bunch of code goes here
echo 'Runtime: '.number_format(microtime(TRUE)-$startTime, 3);
</pre>
<p>In most cases this works. But I was looking to track a bit more then load time while testing my upcoming PHP 5.3 framework. So I created a little script that tracks load time, page your visiting, memory used in the script and date and time of visit. Its not very impressive but I figured I would share with everyone in-case your looking for something similar. So with out further ado&#8230;</p>
<pre class="brush: php; title: ; notranslate">
/**
 * Extra Just for Testing
 */
$memStart = memory_get_usage();
$startTime = microtime(TRUE);
/**
 * End of Extra
 */

// All the same code here

/**
 * Extra Just for Testing
 * echos full runtime and memory for this and last request
 */
$memEnd = memory_get_usage();

// Put this here so the file stuff does not scew the memory numbers
$line  = '&lt;br /&gt;Runtime: '.number_format(microtime(TRUE)-$startTime, 3);
$line .= ' &lt;br /&gt;Memory: '.number_format(($memEnd - $memStart)/1000, 2, '.', ',').'KB';
echo $line;

if(!file_exists('benchmark.log')) {
    $file = fopen('benchmark.log', 'x+');
} else {
    $file = fopen('benchmark.log', 'a');
    fputs($file, &quot;\n&quot;);
}
$timeDate = date('m/d/Y H:i:s');
$uri      = $_SERVER['REQUEST_URI'];
$line = str_replace('&lt;br /&gt;', '', $line);
fputs($file, &quot;[$timeDate] - [$uri] - $line&quot;);
fclose($file);
/**
 * End of Extra
 */
</pre>
<p>This will echo something similar to:<br />
Runtime: 0.021<br />
Memory: 195.62KB<br />
on your page, but will create a benchmark file to track all of the page loads so you can track what your changes are doing to memory usage and load time. The lines in that file look something like:<br />
[05/14/2010 03:07:39] &#8211; [/var/www/imorf/public/] &#8211; Runtime: 0.017 Memory: 196.22KB</p>
<p>I hope this helps some of ya&#8217;ll out with tracking code changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/php-benchmarking/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ActiveRecord in PHP</title>
		<link>http://www.christiansouth.com/php/activerecord-in-php/</link>
		<comments>http://www.christiansouth.com/php/activerecord-in-php/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 23:48:30 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=18</guid>
		<description><![CDATA[ActiveRecord implementation in PHP...]]></description>
			<content:encoded><![CDATA[<p>While writing the DB classes for Aero I thought it would add in a simple ActiveRecord example for easy creation and updating of database rows. Since Aero isn&#8217;t quite done I thought I would release just this class for anyone that would be interested in something like it. Its only about 200 lines of code (Commented &#8211; only half that without them. This particular class was made to work directly with the database adapter from Aero but you could easily modify it to work with your database implementation.</p>
<p><!-- MORE --><span id="more-18"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
namespace Aero\Model\Db;

class Record
{
    protected $_adapter;
    protected $_table;
    protected $_tablePrefix;
    protected $_primaryKey = 'id';
    protected $_info = array();
    protected $_originalInfo = array();

    public function __construct($id = 0)
    {
        $this-&gt;_adapter = \Aero\Controller\Application::getInstance()-&gt;db;
        $this-&gt;_getTableInfo();
        if($id !== 0) {
            $this-&gt;getRecord($id);
        }
    }

    public function __set($key, $value)
    {
        // If the key isn't there it doesn't belong in the database
        if(!isset($this-&gt;_info[$key])) {
            return null;
        }

        $this-&gt;_info[$key] = $value;
        return $value;
    }

    public function __get($key)
    {
        if(!isset($this-&gt;_info[$key])) {
            return null;
        }

        return $this-&gt;_info[$key];
    }

    public function getRecord($id)
    {
        $stmt = $this-&gt;_adapter-&gt;select()
                               -&gt;from($this-&gt;_table)
                               -&gt;where(array($this-&gt;_tablePrefix.$this-&gt;_primaryKey =&gt; $id))
                               -&gt;getStatement()-&gt;execute();
        $info = $stmt-&gt;fetch();
        foreach($info as $field =&gt; $value) {
            $field = str_replace($this-&gt;_tablePrefix, '', $field);
            $this-&gt;_info[$field]         = $value;
            $this-&gt;_originalInfo[$field] = $value;
        }
    }

    protected function _getTableInfo()
    {
        $info = $this-&gt;_adapter-&gt;getTableFields($this-&gt;_table, $this-&gt;_tablePrefix);
        foreach($info as $field) {
            $this-&gt;_info[$field]         = '';
            $this-&gt;_originalInfo[$field] = '';
        }
    }

    public function save()
    {
        if($this-&gt;_info == $this-&gt;_originalInfo) {
            return true;
        }

        if($this-&gt;id !== '') {
            $query = 'UPDATE '.$this-&gt;_table.' SET ';
            foreach($this-&gt;_info as $field =&gt; $value) {
                if($field !== $this-&gt;_primaryKey) {
                    $field = $this-&gt;_tablePrefix.$field;
                    $value = $this-&gt;_adapter-&gt;quote($value);
                    $updates[] = &quot;$field=$value&quot;;
                }
            }
            $query .= implode(', ', $updates);
            $query .= ' WHERE '.$this-&gt;_tablePrefix.$this-&gt;_primaryKey.' = '.$this-&gt;_originalInfo[$this-&gt;_primaryKey];
            if($this-&gt;_adapter-&gt;exec($query)) {
                return true;
            }
        } else {
            foreach($this-&gt;_info as $field =&gt; $value) {
                if($field !== $this-&gt;_primaryKey) {
                    $columns[] = $this-&gt;_tablePrefix.$field;
                    $values[]  = $this-&gt;_adapter-&gt;quote($value);
                }
            }
            $query  = 'INSERT INTO '.$this-&gt;_table.'('.implode(', ', $columns).')';
            $query .= ' VALUES(' . implode(', ', $values).');';
            if($this-&gt;_adapter-&gt;exec($query)) {
                return true;
            }
        }

        return false;
    }
}
</pre>
<p>This whole class is not that complex. To use it you would simply extend the class like so:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class User extends Record
{
    protected $_table = 'users';
    protected $_tablePrefix = 'user_';
}
</pre>
<p>Then to use it you would simply some something like:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$user = new User(); // Creates new user
$user-&gt;login = 'username';
$user-&gt;password = hash('sha512', 'password');
$user-&gt;save();
</pre>
<p>Well I hope this helps someone. I know the class isn&#8217;t perfect but again I&#8217;m just trying to share.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/php/activerecord-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML Anchors</title>
		<link>http://www.christiansouth.com/html/html-anchors/</link>
		<comments>http://www.christiansouth.com/html/html-anchors/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 03:50:19 +0000</pubDate>
		<dc:creator>Christian South</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Cross Browser Capatibility]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://christiansouth.com/?p=14</guid>
		<description><![CDATA[A topic that doesn&#8217;t come up that much anymore are anchors. I don&#8217;t find an occasion all that often that I have to use them but every now and then I will get a client that has a page that is fairly long and they want to include them. In a specific instance that came [...]]]></description>
			<content:encoded><![CDATA[<p>A topic that doesn&#8217;t come up that much anymore are anchors. I don&#8217;t find an occasion all that often that I have to use them but every now and then I will get a client that has a page that is fairly long and they want to include them. In a specific instance that came up this week the client has a CMS that they use to enter content for their site. The client had a page with 2 anchors that were something like:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a name=&quot;anchor1&quot;&gt;&lt;/a&gt;
...
&lt;a name=&quot;Anchor2&quot;&gt;&lt;/a&gt;
</pre>
<p>Now to most people this wouldn&#8217;t be too much of an issue except when linking to them with the following</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;#anchor1&quot;&gt;Click Here&lt;/a&gt;
...
&lt;a href=&quot;#anchor2&quot;&gt;Click Here&lt;/a&gt;
</pre>
<p>Now here there is one subtle difference, in the name attribute on the second anchor tag the &#8220;a&#8221; is capitalized. And here is where it gets a bit fishy. In Internet Explorer and Chrome both of these examples work perfectly. Firefox on the other hand will have a problem with the second. It seems that the anchors are case sensitive in Firefox so it literally looks for an &#8220;a&#8221; tag with a name of &#8220;anchor2,&#8221; but all we have is one with a name of &#8220;Anchor2.&#8221;</p>
<p>&nbsp;</p>
<p>The easiest fix for this is to ALWAYS use lowercase names for the anchor names, but we all know asking a client/site user to do this will almost never get you anywhere, so I will recommend the following&#8230; REGEX! Simply search the content provided by the user for a name attribute an simply convert it to all lower case. You will of course have to do the same for any tags pointing to that anchor.</p>
<p>In conclusion.. I hate cross browser testing. <img src='http://www.christiansouth.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I can&#8217;t really call this a bug due to the fact that I use *nix based systems most of the time and I&#8217;m used to case sensitivity, but I would like to see this fixed in Firefox. If anyone has any thoughts please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christiansouth.com/html/html-anchors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

