PHPList Tweak for Plain Text Version of HTML Mail

This small alteration to the PHPList code will produce better line breaks.


  $text = preg_replace("/<\/p\s*?>/i","<\/p>\n\n",$text);

Keyword Analysis or Discovery (a first try)

I was messing around with some textual analysis, trying to figure out how to do a "related articles" feature in Drupal.

Testing for Hack Scripts, Scan Your Uploads

This was ripped from a patch I made to ZenCart to deal with malicious uploads. It was stripped from a class, and it should probably be worked into pretty much any uploader class. (The class is in upload.php)

It doesn't handle binary files, but it's good with scripts.

Convert Text to HTML PHP Function

How many times has this wheel been reinvented? According to Google searches, not enough - because I couldn't find a good one. Over the years, I've built this wheel a few times, so, here goes again. This is a lot better than the stock nl2br() function.

The attached code and test files show it off, and only a description follows.

More on Iterators and Iteration

Iterators are one of my favorite language features or design pattern. They're a feature that, when done correctly, basically vanishes.

Turn URLs into Links Without Affecting Existing Links (and a gripe about collective stupidity)

This is one of those problems that has been solved, but, it's been solved in incomplete ways so many times that these not-too-useful answers outnumber the useful answers, totally messing up web searches. This consequently seeds the idea that this is an intractable problem! Even at stackoverflow, they say it's really tough.

Evaluation and Variables

<php echo 1; ?>

<php echo 1 + 2; ?>

<php echo 2 * 3; ?>

Another Cheap Thumb Gallery Maker

One thing about scripting is that, sometimes, a little fragment of code will get used over and over, and it's not a full-featured app. This script just looks over a directory full of specially named files, and produce a "photo gallery" for it.

Hundreds of these scripts have been modified to do all kinds of cool things, but this one doesn't do any of those things. The script just gets copied into a directory, and it produces an index of images.

Scripts like this won't ever die. They won't get replaced by more elaborate scripts.

Arrays and References Gotcha, Array Passed by Value Behaves Like Array Passed by Reference

In PHP 5, when you pass an array by value, but the array contains references, then, you will get some subtly weird behavior.

Basically, when you copy an array of references, the references still refer to the same variables. So changes to those variables aren't local to the function.

~~~~ $args = array(); $args['x'] =& $_REQUEST['x'];

echo "




echo "



$x = $_REQUEST['x'];

echo "


Wacky VBA, Bitchen PHP

I was spending a night debugging some heinous VBA code. It was my code, but it sucked. It sucked because it's pretty hard to write glue code that integrates different parts of MS Office. All I wanted to do was produce some distribution lists from an Access database, but thanks to Office Outlook's totally complicated system of managing email lists, you can't just spit out something like the old .alias file:
That would be easy. No, Outlook requires you to make a DistributionListItem, and then AddMembers to it.

CSV Files, Comma Separated Values

This is the latest version of the CSV class, but renamed to work with CakePHP.

The main change is the addition of a feature that will let you save the headings into the object, then parse lines and return them as associated arrays rather than numerically indexed arrays.

Here's some sample code showing how to use it, followed by the class:

~~~~ $csv = new csvComponent(); $fh = fopen($filename, 'r'); // First, detect the headings -- this feature allows us to put some // information above the actual data. while( $data = fgets( $fh ) ) { $line = $csv->textToArray( $data ); if (p

CakePHP Dates are Nice

	Date: <?=$html->monthOptionTag( 'Phoneproject/Date' )?> -
		<?=$html->dayOptionTag( 'Phoneproject/Date' )?> -
		<?=$html->yearOptionTag( 'Phoneproject/Date' )?>

Terse Javascript Alternations, and the Frameworks' Problem with SQL


Here's a snippet of javascript that breaks up a phone number into its parts, if it's formatted in the common formats.

    var cell = namesArray[rownum]['Cell'];
    (cell_parts = /\((\d\d\d)\) (\d\d\d)-(\d\d\d\d)/.exec(cell)) ||
    (cell_parts = /(\d\d\d)-(\d\d\d)-(\d\d\d\d)/.exec(cell))     ||
    (cell_parts = /(\d\d\d)(\d\d\d)(\d\d\d\d)/.exec(cell))       ||
    (cell_parts = ['','','',''])

It's pretty short, no?

What's nice about it is that it parses several formats, but doesn't collapse all these possibilities into a single regex.

Hierarchical Report Generator for CakePHP

This is a CakePHP component to create hierarchical reports.

It's not really canonical Cake, because it only works with MySQL.

It basically works, but is rough. It can be used in a non-Cake context, to some extent.

A hierarchical report is just a report with several reports in it, and they are arranged hierarchically. For example, this reports on attendance at an event, for several events, on several different dates.

Common MIME Types, in PHP

This is based on a list of common MIME types that's been posted around the web. It's in PHP array format. The long list cannot be used as-is due to repeated keys. The long list is followed by a shorter sublist of popular formats you're likely to need.

Syndicate content