PHP Socket Implementation and Webpage Downloader

This post reveals two handy PHP constructs I’ve been using for a while now: a Socket class and a webpage-downloading function.
The files:

Socket.php (highlighted; plaintext)
webpage.php (highlighted; plaintext)

What good is a full-on Socket class and function, you may ask, when you can simply run file_get_contents with allow_url_fopen turned on? Well, consider that you want to send [...]

Comments Off

PHP Templating: Variable Date

In building a template system, you may want some way to inject date info using a timestamp (perhaps generated through mktime() ) and date(). But you don’t want the format to be dependent on the template parser, but rather specified through the variable in the template itself.

$template = preg_replace(
"#\%date(\:\s*(.*?))?\%#ei",
[...]

Comments Off

A Method for CSS Variables

Jay Salvat at nettuts has written an article on adding variables to your css files. I like the approach, which includes caching the results, though the code presented is not 100% secure, as commenter Pelle has noted.
As for the most popular response, having apache run css files as php code, there are a few [...]

Comments Off

A Couple Little PHP Array Tricks

Maintaining array indexes after deleting an element; selecting a random element from an associative array.

Comments Off

Rounded Corners at the Src

CSS-based rounded corner solutions are excellent for website layouts, but it’s just downright silly to envelope a single img tag with two to four extraneous divs just to get some nice rounded corners on that one image. PHP (with its GD library) is excellent for this purpose.

Image: Warped by ~eternicode (me).
My PHP script can [...]