My Best Friend

Uncategorized 6 Comments

I recently discovered a lump on my best friend Noggin which the veterinarian
determined needed to be removed. You can keep track of his progress on this page. We'd appreciate any prayers, positive vibes, and/or incantations on Noggin's behalf that he get through this OK and the biopsy comes up negative.

As you might imagine, Noggin will have the bulk of my attention in the near future over comparatively trivial things like this blog.

NetBeans IDE and PHP

PHP 1 Comment

I just noticed in a web advert that the NetBeans IDE has a PHP plug-in. Having still not settled on a PHP editor/IDE that I'm really comfortable with, I downloaded NetBeans and will be giving it a test drive.

My first impression is that it's peppier than the various Eclipse-based editors I've tried (including Apatana most recently). I still have a lot of digging, experimenting, and reading to do to find out how well it meets my needs; but I thought I'd post this now in case anyone beside me also thought NetBeans was only for Java and might like to take a look at it, too.

CodeIgniter Framework Looks Promising

PHP 1 Comment

It's been almost a month since my last article. It seems work and other aspects of my life have contrived to keep me plenty busy lately. So to keep some level of activity going here, I thought I'd mention one of the things I've been up to lately.

I've been looking at a few PHP frameworks over the last several months as time permits (i.e.: not often!). The latest one I've tried is CodeIgniter. My initial impression is very positive--this one might be a keeper.

One thing I like about it is that it does not dictate a specific methodology with an iron fist. But what really stands out to me compared to others I've looked at is the quality of its documentation. Take a look for yourself at the online copy of the user manual, and I think you'll see what I mean.

If you're in the market for a PHP framework and have found others to be too inflexible and/or too difficult to learn, take a look at CodeIgniter and see what you think.

Sub-Domains on Windows localhost

General 2 Comments

I find it useful when working on a web project to set up a sub-domain on my development PC's "localhost" Apache installation. This allows me to test the project by accessing pages via that sub-domain, treating the directory being used as the root of that sub-domain as if it were the web document root directory (i.e.: $_SERVER['DOCUMENT_ROOT'] in your PHP scripts will point to that directory when the page is launched via that sub-domain).

Setting up a localhost sub-domain in an Windows/Apache environment is fairly easy. You just need to set up a few lines of text in three files, then restart Apache. First, make sure that your Apache httpd.conf file has the following in it, adjusting the path to the "httpd-vhosts.conf" file as appropriate for your installation:

Read the rest...

Filtering MS Word Text

HTML, PHP No Comments

A common annoyance when dealing with user-supplied content is the way MS Word uses some non-standard character encodings (at least non-standard in terms of the web). Among others, these include the directional (a.k.a. "smart") quotes. The problem occurs when you output text that contains those characters as a result of a user copying and pasting text from a Word document. Typically they are not interpreted by the browser and the font being used, resulting in the dreaded place-holder characters (question marks, boxes, etc.).

If outputting the UTF-8 character encoding in your PHP pages, I came up with the following PHP function to help deal with this. It is inspired by this comment on Chris Shiflett's blog. It is simply a use of the str_replace() function to replace some known problem characters with character entities that should work better when outputting UTF-8 content.

<?php
function filterText($text)
{
   $search = array (
      '&',
      '<',
      '>',
      '"',
      chr(212),
      chr(213),
      chr(210),
      chr(211),
      chr(209),
      chr(208),
      chr(201),
      chr(145),
      chr(146),
      chr(147),
      chr(148),
      chr(151),
      chr(150),
      chr(133)
   );
   $replace = array (
      '&amp;',
      '&lt;',
      '&gt;',
      '&quot;',
      '&#8216;',
      '&#8217;',
      '&#8220;',
      '&#8221;',
      '&#8211;',
      '&#8212;',
      '&#8230;',
      '&#8216;',
      '&#8217;',
      '&#8220;',
      '&#8221;',
      '&#8211;',
      '&#8212;',
      '&#8230;'
   );
   return str_replace($search, $replace, $text);
}

// USAGE:
header('Content-Type: text/html; charset="UTF-8"');
echo filterText($test);
?>

UTF8 in PHP and MySQL

PHP 3 Comments

The intent of this article is to tie together some things I've learned to do in order to get my web apps to "play nicely" with the UTF8 character set. Before we go any further, let me state that I do not claim to be an expert on this; the following is simply a collection of things I've discovered here and there on the web, and which together seem to help smooth out most of the bumps in the road of using UTF8.

So let's start with the database itself. To get your varchar and text fields talking UTF8, you should assign both the character set and a corresponding collation. (See the MySQL manual section on character sets and collations to see the differences between the various collation types.) You can assign this stuff at the field level should you desire, but generally I just assign it at the table level:

Read the rest...

Calculate Age: One-Liner Fun

PHP 1 Comment

Here's a little one-liner I thought up today for this PHPBuilder forum thread. It's purpose is to calculate someone's age when you know the year, month, and day of their birth (integer values). In this snippet it is assumed that $year, $month, and $day hold the integer values for the birthday of interest.

$today = time();
for($yr = $year, $age = -1; mktime(0,0,0,$month,$day,$yr) < $today; $yr++, $age++);
echo $age;

This utilizes the often ignored fact that you can use comma-separated statements for the first and third expressions in the for loop definition list.

« Previous Entries