June 18th, 2009 under php, web
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 [...]
March 28th, 2009 under blogs, design, php
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",
[...]
March 19th, 2009 under css, php
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 [...]
February 14th, 2009 under asides, php
Maintaining array indexes after deleting an element; selecting a random element from an associative array.
February 8th, 2009 under php, web
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 [...]