PHP

No Eval? Variable Interpolation on PHP Code

We recently turned off the websites' ability to use the eval() or related functions. In a small CMS I'd written a while back, I was using eval to interpolate variable names in strings. This was a simple way to do "lazy evaluation" on strings I was using as templates. With eval, there was no need to use a special templating syntax - the syntax was PHP's.

Now, with eval turned off, I needed a function to interpolate variables in a string.

TXTMOB for Web Hosts (project)

This is a hack of txtmob that's being developed to run on cheap web hosts.

So far, it'll let you send to the group via the web form, so it's suitable for a one-way, moderated list. Good for news.

The sms forwarding feature doesn't work, so, it's not able to do "real" txtmob yet. Maybe it will one day... This code is very alpha, and based on code from SourceForge, that was at version 0.14, so you know what you're getting :-)

I'm not forking the project. This is just a personal fork for personal use.

Fun Details, and Some Roadmapping

Object-Oriented Parser for iCalendar

Been working on a parser for ICS files, and it's done in an OO style - so that parts of the data become instantiated as objects, and the parse tree is a hierarchy of objects.

Participate: Social Networking Software


This is a social network that was written back around 2004. My friends were doing a distributed anti-war protest. It was basically not that well attended, because people weren't really aware that the President was a liar, and that he would eventually suspend habeas corpus. On top of that, it was in competition with another demo, and that really killed it. The software did so-so, but it got taken down after the demos, because I got paranoid about the cops subpoenaing the entire database.

Also, the software was kind of hard to use. A lot of features were basically implicit, and you had to be pretty savvy to "get" it. Still, a lot of Friendster features were ripped off, and a couple features, like the double-blind email-based contact system were cool.

Cleanup Your HTML: A Tag Closing Function

User-submitted HTML often contains small markup errors that can affect other parts of the page. The most common are unclosed tags that cause text to be bolded, italicized, or linked all the way down the page. The visual effect is catastrophic, though the error is really minor.

The html_close_tags() function scans HTML code, and generates a string that will close all the open tags. An easy way to use it is like this:


  $html = $html.html_close_tags($html);

Associative Array (Hash) Tricks in PHP

Suppose you're tallying some data. You want to know if a value has shown up in the data. You can do this by using the array, like this:

$tally = array();
while( $row = getData() )
    array_push($tally, $row);
if (in_array($tally, 'theValueIWant'))
    echo "yes";
else
    echo "no";

There's a faster way, by using the array key. (It should be faster.)

Novice's Notebook

This is a repository of "novice" articles, written with the intent of driving more traffic to the site, and getting more ad clicks. It's pretty crass, I know, but the information may be very useful.

Classes to Create htdigest and htaccess Files

This is a first draft of some classes to manipulate .htaccess and htdigest files. I'm putting it up because there aren't many classes to do this, and seemingly none for htdigest files. (I just learned about the PEAR::Config classes. Neat.)

HTAuthFile is a superclass with a common writer. HTAccessFile is a very incomplete way to manipulate Apache .htaccess files.

htdigest Password Function in PHP

This is a function to change a password within an htdigest password database file. htdigest is one method of user authentication in Apache HTTP Server.

Global $htdigest contains a path to the htdigest file. Global $domain is the security domain.

The htdigest formula for the hash is: md5("$username:$securitydomain:$password")

htdigest is like htpasswd, except it uses the md5 hash for hiding the password, and it supports digest authentication.

Ugly XML Parser Code to Generate INSERT Statements

Code this ugly should be illegal. It does what it says, though.

I'd add some sample data, but this is just too far in my past. The original data was just an xml file with tags going two levels deep.

~~~~ <?php

if (!

Spy on Internet Users with: 1-Pixel GIF File, in Base64

This little bit of code returns a 1-pixel gif file. You can add it to the bottom of any script that you want to call from an IMG tag.


<?php
header('Content-type: image/gif');
echo base64_decode('R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
?>

Oldie but a Goodie: Hierarchical Menu Rendering

I've been coding on experts exchange, testing myself. Here's some relevant code for one of the answers.

They're classes that have been used to generate hierarchical menus.

PHP Notebook

Lately, I've been doing a lot of PHP work.
This is a notebook of some things learned. It's not definitive, or even correct, but it may prove useful.

Syndicate content