"We can't solve problems by using the same kind of thinking we used when we created them." - Albert Einstein

Monday, April 26, 2010

My Own Syntax Highlighter

Let me start of by saying that there are a lot of great syntax highlighters out there. Certainly we don't need another one. That being said, I did create one, but not for any other reason than I wanted to see what was involved. It is not a complete highlighter in that not all scripting languages are covered. Basically, I just covered the languages I use most often, which are HTML, PHP, CSS, JAVASCRIPT, DELPHI and XML. You can try out a demo of the highlighter by clicking on the link below.

Syntax Highlighter Demo

The the following code in this blog was generated by this syntax highlighter.

I started off working on the HTML and decided to go the old C++ route and parse the script one character at a time. This worked out quite well as it was easy to identify the tags, tag name and attributes without having to iterate through a list of all the HTML tags and attributes. Also, this works well for XML as well where there aren't any standard tag names.

continue »

delicious digg facebook stumble twitter myspace linkedin technorati reddit google springpad blogger | addthis Share More...
 

Tuesday, April 6, 2010

PHP Log Script

When doing any kind of programming, including programming in PHP, it is almost essential to create a log file of background processes just to know what is going on. Besides being of help to your users, this is a great way to track bugs in your programming  as well (not that we ever write imperfect code!). I recently needed to track some simple procedures and created a fairly simple class to implement a log of what was going on in a separate thread on the server. I've included the code for the log class here for your use if you find it useful at all.

Using the class is simple. Just put the class file in your includes directory, reference it in your script, and create a new log object. Then write to the script whenever you need to keep track of something.

<?php
include('../include/classes/logfile.php');

$log = new Logging();
$log->log_message("Log file started");
...
?>

By default, the log will be written to the current directory using the file name of logfile_(current date).log. This is easily changed by overriding the default values as decribed below.

continue »

delicious digg facebook stumble twitter myspace linkedin technorati reddit google springpad blogger | addthis Share More...
 

Saturday, March 20, 2010

Date Picker

A Javascript Calendar and Date Picker Solution

Have you ever needed to create a form that allowed the user to select a date from either a series of combo boxes for month, day and year, or by using a calendar date picker. User a date picker is relatively easy, and I've chosen to use the Date-Picker Widget V5 available from the frequency decoder website. The problem comes with wanting the combo box for the days of the month to accurately represent the selected month, whether the user selects the month using the combo box or the date picker. Also, the days of the month need to be correct for the month of February if it is a leap year or not. The script below will accomplish both using three combo boxes for the day, month and year coupled with the Date-Picker Widget V5.

 



Check out the DEMO here.

The trick is to get the combo boxes working in sync with the calendar date-picker. Here's how...

continue »

delicious digg facebook stumble twitter myspace linkedin technorati reddit google springpad blogger | addthis Share More...
 

Wednesday, February 17, 2010

AJAX Style File Upload

Easily Upload Files Without Refressing The Page

Ever wanted to upload files using AJAX without reloading the page? There are a number of sites that describe how this can be achieved. For the most part, the effect is achieved using iframes and javascript. This tutorial will go through the process of creating a file upload AJAX form and a PHP script which will return a status of 'success' or 'error', as well as, a few other details about the upload. To simplify the whole process, I found that using jQuery and the jQuery Form Plugin is the easiest and best solution for getting this done quickly.

Try the DEMO for this tutorial.

This exurb from the jQuery website provides a good starting point and overview of what we want to achieve.

The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajaxSubmit, gather information from the form element to determine how to manage the submit process. Both of these methods support numerous options which allows you to have full control over how the data is submitted. Submitting a form with AJAX doesn’t get any easier than this!



 

Basically, we are going to create a form that lets us gather some basic information and select a file for upload. If any of the fields are left blank, we will receive an error message. If the file is not an image file, we will also receive an error message. If everything goes right, the file is uploaded and the file name, ext are returned. While uploading, the screen will display a message box advising that a file is being uploaded and we should wait.

So, let's get right to it.

continue »

delicious digg facebook stumble twitter myspace linkedin technorati reddit google springpad blogger | addthis Share More...
 

Wednesday, February 10, 2010

PHP File Upload

Easy File Upload Funtion for PHP

Recently, I needed to create a script to upload and parse a file using ajax. As is well known, you cannot upload files using javascript or ajax. However, there are ways to make it appear to be done using ajax. Anyway, in the course of trying to find something I could use effectively, I came across a small script that manages the upload part. For the most part it did everything I wanted, but found there could be some improvements. The original script was written by Binny V A and found on this website: http://www.bin-co.com/php/scripts/upload_function/

Here I am just going to present this function. Soon I will present a full ajaxform script to upload files using this upload function.

Uploading a file is usually not just a one-line function. There are a number of elements that need to be checked and verified before a file can be successfully uploaded. I have made a number of improvements to the original function. Some deprecated code has been updated. Some functions that did not work have been updated. If the upload destination folder does not exist, it will now be created. You can now choose to overwrite an existing file with the same name or create a unique name for the file (appends a numerical to the file name).

continue »

delicious digg facebook stumble twitter myspace linkedin technorati reddit google springpad blogger | addthis Share More...
 

Tuesday, January 19, 2010

Add Watermark / Background Image to Listview

After using the listview component for awhile, undoubtedly you will want to add a background image or a watermark to the background just like Windows Explorer does for the My Music or My Videos folders. A watermark is simply a background image that stays in the bottom right-hand cornor of the listview. Seems simple enough. A quick Goggle search for "listview background image" turns up countless results which range from using a custom owner-drawn technique to using built-in properties for some of the newer versions of Visual Basic or Visual C++.

Background Image
It quickly becomes obvious that adding a background image can be accomplished in any number of ways. And, that no one really seems to know how to add a watermark to the listview the same way that Windows Explorer does. Searching through the Mircosoft documentation for the listview control uncovers the Windows message LVM_SETBKIMAGE and the LVBKIMAGE record or structure. It would seem that this is a good place to start.

There are three key members of the LVBKIMAGE structure which determine how (and if) a bitmap image is displayed in the listview. The three members are ulFlags, hbm, and pszImage. There are three flags to indicate the source of the image, and two flags to indicate the style. The source flags are LVBKIF_SOURCE_NONE, LVBKIF_SOURCE_HBITMAP, and LVBKIF_SOURCE_URL. These three source flags are defined as follows:

LVBKIF_SOURCE_NONE
      The list-view control has no background image.
LVBKIF_SOURCE_HBITMAP
      A background bitmap is supplied via the hbm member of LVBKIMAGE.
LVBKIF_SOURCE_URL
      The pszImage member contains the URL of the background image.

The LVBKIF_SOURCE_NONE flag when set produces obvious results. No background image is displayed.

The LVBKIF_SOURCE_HBITMAP flag is interesting in that the Microsoft documentation indicates that the hbm member is "not currently used". Interesting that there is a flag for a bitmap handle that is not used. As we'll see later, it is more that using the hbm member is undocumented, rather than unused.

continue »

delicious digg facebook stumble twitter myspace linkedin technorati reddit google springpad blogger | addthis Share More...

categories

Popular

newsletter

Get occasional email updates from kidmoses

donate

Donations of any size to this website are greatly appreciated.

Donate
copyright © 2004 to the present day | web design by Top Place Web Solutions
privacy | terms | login | contact