Templating with DOM

DOMTemplate is a new templating system that doesn't use any markup.

PHP DOM to Implement a Form Class with Pure HTML Templates

So, I had this painful gout attack today and was mostly bedridden. It sucked. But I got some reading done, which was nice. My mind wandered and came up with this idea (and a headache).

Comparison Shopping for Toilet Paper, in multiple computer languages.

It's hard to concentrate when you're tired and cranky, so I wasted some time writing a simple calculator in several different languages.

Heuristics are Nice : (working toward) Facebook-style Previews

I was thinking about how facebook updates parse out the url, then construct a nice looking preview. I think what it takes is scanning the textarea for a url, and then using ajax to tell the server to fetch a summary of the page at the url. get the data back, and insert it into a template, and reveal it.

Chant Down Babylon! Character Set Conversion from Latin-1 ISO-8859-1 cp1252 to UTF-8

I swiped this code from

Character set conversion is one of those things I've avoided over the years. Just use UTF-8 from the start. But IMC has thousands of articles stored as a BLOB datatype, so that it's text in various character sets. The software in front of the data was using ISO-8859-1, but PHP wasn't really mangling the data -- it just passed the binary through unchanged, until I installed the mbstring extension (or more accurately, it was baked into PHP). That caused some problems, and it snowballed into converting everything to UTF-8.

Learning the Facebook API

For the past few months I've been working on web apps. The first was a mobile site based on jQuery Mobile. While it was "cool", it quickly dawned on me that it wouldn't get any significant usership. For one, it was like a clone of 4square and Scvngr - and who really uses that? I'd peer into the lists of checkins, and it wasn't looking too encouraging. People use it when they're bored and alone, and my scenario didn't involve either of those situations.

PHP Namespaces with Autoloader Example

It took a while to wrap my mind around PHP namespaces - despite the fact I've needed them for years. It's just one of those features that seems weirder in PHP than in other systems. But that's normal for PHP - quirky. Unfortunately, it's not quirky like Perl, where the quirk eventually makes you feel good. With PHP you just feel kind of odd, maybe a little inferior... like your language is slipping toward becoming the Visual Basic of the web.

PHP Runs an Old Version of PCRE Causing Problems with Drupal and MediaWiki

This seems to happen a lot - and it took several searches and many pages of reading to find the solution. This page will try to even the odds a little more.

The solution was found here: PCRE Problem Appearing in PHP Related to Apache Webserver

After building a new Apache, then a new PHP, and configuring both, Drupal started throwing error messages "Compilation failed: this version of PCRE is not compiled with PCRE_UTF8 support".

Hacker Scripts Decoded: eval gzunzip base64_encode str_rot13

I got hacked (more than once) and they installed a backdoor php shell. It sucked (and I must suck for allowing it to happen... but anyway) and here's a snippet of code that you can use to decrypt these nasties. To use it, paste the function definition for "dc" below into the hack script. Then replace that first instance of "eval" with "dc", which calls this function. Then run the script. The output will be the source of the script. View source to read it formatted correctly - and use Save As... to save it. You may need to edit the output to get it working.

function dc($s) {

A Demo of Transmitting Passwords Encrypted

This is a demo of a technique to transmit password encrypted. It's not a perfect solution yet, but it's getting there.

Mass Convert IP Addresses to Domain Names with a Filter

A PHP script to convert many IP addresses to domain names.

Protect Your Website from Malicious Input: Validation with Filters

For years (and years) we've done data validation in PHP "by hand" either with string functions or with regular expressions. The problem with PHP has been that, well, PHP programmers aren't so great at regexs. Also, unlike Perl, there's no data tainting feature that forces you to validate your inputs before they're used in expressions. (Correction, there is a tainting extension.) The upshot is that a lot of bad data gets through. PHP finally added some data validation functions, but it seems like nobody is using them. It still lacks tainting. The former problem, we can address.

VI and Ctags Makes Browsing Code Easier

Vim/GVim has great features to make it easy to read C (and PHP and Perl) code. They treat your code like a hypertext or web page, where you can jump between files easily.

First is the "go to file" feature. If you move the cursor onto a file name, and type gf, you'll be taken to that file. To return to the previous file, press Control-o. The file opens are kept on a stack, so you can drill down into file, and climb back out.

Decoding gzinflate base64_decode

Some themes add a copyright notice using a technique also seen in hack scripts. They take the PHP code, and the base64 encode it, and gzip it.

Caching Data for AJAX with Javascript

Here's a way to cache data on the client side, via javascript. This was tested on Firefox 3.6.3 on Ubuntu.

The idea is to convert your data into Javascript, and then load it with the SCRIPT tag. You then use the Expires HTTP header to tell the client how long to cache the data. Finally, you use some Javascript code to display the data.

Syndicate content