How To Extract HTML Tags And Their Attributes With PHP

October 20th, 2009

There are several ways to extract specific tags from an HTML document. The one that most people will think of first is probably regular expressions. However, this is not always – or, as some would insist, ever – the best approach. Regular expressions can be handy for small hacks, but using a real HTML parser [...]

Continue Reading...

Calculating Readability Metrics In PHP

April 28th, 2009

Readability metrics, also known as readability formulas, are a set of algorithms that estimate the readability of text. Most tests are fairly primitive as they only take into account things like sentence length and the average number of syllables per word, but ignore deeper factors like sentence structure and semantics.
Still, readability metrics can be useful [...]

Continue Reading...

Text Classification With PHP

March 7th, 2009

Text classification is probably the most popular real-world application of machine learning and other AI techniques. This is because the adaptive spam filters that guard our inboxes, comment forms and guestbooks are basically specialized text classifiers that only deal with two categories – “spam” and “not spam”. Text categorization can also be used to detect [...]

Continue Reading...

Make Your Plugin Faster With Conditional Tags

February 22nd, 2009

One of the reasons why WordPress can be slow is that it loads all active plugins on each and every page, even if some of those plugins aren’t actually used on that page. For example, an active anti-spam plugin will still be loaded even if the current page doesn’t contain a comment form (e.g. category [...]

Continue Reading...

Get Google Search Results With PHP – Google AJAX API And The SEO Perspective

January 5th, 2009

If you’ve ever tried to write a program that fetches search results from Google, you’ll no doubt be familiar with the excrutiating annoyances of parsing the results and getting blocked periodically. Run a couple hundred queries in a row and bam! – your script is banned until proven innocent by entering an captcha. Even that [...]

Continue Reading...

Fast Weighted Random Choice In PHP

December 10th, 2008

Sometimes you may need to randomly select items from a list so that some items are selected more frequently than others. For example, you might take a list of applications and their download counts, and randomly pick a “featured application” based on the number of downloads.
There are several ways to accomplish this in PHP. [...]

Continue Reading...

Cross-Domain POST With JavaScript

November 20th, 2008

Normally you can’t send cross-domain requests in JavaScript due to restrictions imposed by the same-origin security policy. There are many clever hacks that circumvent this by using remote script includes (even CSS includes) or proxy scripts, but so far I haven’t seen anything useful for client-side, cross-domain POST requests.
However, it turns out you can [...]

Continue Reading...

Displaying Recent Posts On a Non-WordPress Page

November 15th, 2008

Listing recent posts on a WordPress page is easy – there are various widgets and theme functions available just for that purpose. But what about a non-WP page, or even a different site? That’s not that hard either – simply grab some posts from the blog’s RSS feed and output them on your page. In [...]

Continue Reading...

Parse, Edit And Create Torrent Files With PHP

November 11th, 2008

A .torrent file contains assorted metadata that is stored in a “bencoded dictionary” format. Bencoding is a relatively simple cross-platform encoding used by BitTorrent and a dictionary is basically an associative array. You can find a high-level overview of the file structure here.
To open or edit a .torrent file in PHP you can either parse [...]

Continue Reading...

Private Message Sender Script For vBulletin Forums (PHP)

October 9th, 2008

Random script time!
Here’s a PHP function that can send messages to any user on a vBulletin forum. I wrote it because somebody asked me if I could help with their code and I figured it would be easier to write it from scratch. Also, I predict it will be useful to more than one sentient.
Copy [...]

Continue Reading...

Building a DeviantArt Recommendation Engine

April 29th, 2008

DeviantArt, with its huge number of artworks and a large userbase, is just the kind of site that could use a good recommendation engine. A recommendation engine is basically a program that analyzes your tastes and recommends some images that you might like. There do not seem to be any official plans to create a recommendation system. So I went ahead and started building my own recommendation engine for DA.

Continue Reading...

Simple Text Summarizer In PHP

April 12th, 2008

I’ve written a simple text summarizer that can find the most important sentences in any given (English) text and produce a summary of the specified length. It would be pretty easy to adapt the PHP script to other languages, too.

Continue Reading...

Get Google Image Search Results With PHP

February 28th, 2008

Google Image Search doesn’t get as much time in the spotlight as the “normal” Web Search, but it’s still useful for things like finding suitable illustrations for an article (Flickr also comes to mind). Whatever you use it for, you can often get results faster with a bit of automation. Here’s a simple PHP script that can parse and return the results of any Image Search query. For education purposes only.

Continue Reading...

Random Person Name Generator

February 7th, 2008

I decided to put a person name database I found to good use and make a person name generator. Here it is! The generator uses Markov chains. Most of the source code is available for download.

Continue Reading...

Extracting The Main Content From a Webpage

January 25th, 2008

I’ve created a PHP class that can extract the main content parts from a HTML page, stripping away superfluous components like JavaScript blocks, menus, advertisements and so on. The script isn’t 100% effective, but good enough for many practical purposes. It can also serve as a starting point for more complex systems.

Continue Reading...

Raw HTML Plugin for WordPress

December 13th, 2007

Recently I needed to put some style definitions and a JavaScript function in a post on another blog that I have. I wasted several hours trying to do this, because WordPress insisted on putting backslashes in front of my apostrophes, inserting superfluous <p> or <br /> tags in place of newlines, and generally breaking my HTML in various horrible ways.

In the end I decided to just go and write a plugin that would let me put any code or script in my posts and display it to the visitor unmodified.

Continue Reading...

Detect Users Accessing Your Site Via a Proxy

November 23rd, 2007

The are many reasons why someone might want to detect if users are accessing their site via a proxy. For one, all spammers use proxies. Proxies can also be used to cheat voting systems, create multiple accounts when only one account is allowed or make it appear like the user is browsing from a different [...]

Continue Reading...

Comment Spam Down By 96% – It’s Simple

November 17th, 2007

For months I’ve been getting dozens of spam comments, sometimes over a hundred per day. Most of them are caught by Akismet, which is great. The problem is that with high numbers of spam comments it’s virtually impossible to look through the spam filter logs and de-spam false positives. The bandwidth and processing power wasted [...]

Continue Reading...

Make A WordPress Plugin Now! – Plugin Generators of Doom

November 10th, 2007

I’ve been following WP plugin development-related news for a week or two now, and I’ve noticed something that could make creating a plugin easier – plugin generators. These tools can create a handy template for your new plugin so you don’t need to start completely from scratch; you still need to know (at least) PHP to make your plugin do anything useful, though. In this post I’ll review three WordPress plugin generators I’ve come across.

Continue Reading...

See Which Plugins Have Update Notifications Enabled

November 7th, 2007

I’ve added a new feature to my single-click WorPress plugin updater – now you can see which of your plugins are checked for updates. Those plugins that have update notifications enabled will be marked by a golden bar-thingy in the “Plugins” tab. This is useful to see which plugins will notify you when an update [...]

Continue Reading...

Single Click Plugin Updater WordPress Plugin

October 19th, 2007

This plugin extends the plugin update notification feature introduced in WordPress 2.3 by adding an “update automatically” link to update notifications. When you click the link, the new version of the corresponding plugin is downloaded and installed automatically. It also lets you know which plugins have update notifications enabled.
Update 06.04.2008 : Version 2.0.1 with much [...]

Continue Reading...

How To Run A PHP Script In The Background

October 16th, 2007

If you have a PHP script that takes a while to execute (for example, long database operations or file format conversions), you might want to run it in the background so that the rest of your page still loads fast. In this post I’ll describe two ways to do this.
Launching a background process
One approach is [...]

Continue Reading...

Broken Link Checker Plugin 0.2 Update

October 13th, 2007

The Broken Link Checker Wordpress plugin has been updated to version 0.2! Here’s what’s new -

Link checking algorithm has been improved and shouldn’t generate false warnings anymore.
Links that are discovered to not work will be re-checked again a few minutes later. This is useful if the link only appeared to be broken due to a [...]

Continue Reading...

PHP Frameworks Are Evil

October 10th, 2007

Shoot Yourself in The Foot More Efficiently
If you’re unfamiliar with how frameworks function, trying to use a framework for a new project will bring trouble. With all the complexities frameworks bring, new bugs will come, too. Besides, small one-man projects typically don’t require a framework.
MVC Isn’t A Framework-exclusive Feature
See the bare-bones MVC and the framework [...]

Continue Reading...

How To *Really* Upload Files With PHP

October 8th, 2007

I’ve noticed that whenever I search for a “php upload script” or “how to upload files”, the first page of Gogle results is full of pages that tell you how to handle file uploads = letting users to upload something to your server. But what if you actually want to create a PHP script that [...]

Continue Reading...

See The Most Dugg Sites

October 3rd, 2007

I’ve created an online tool that displays the sites that received the most votes (diggs) during the last 7 days.
Features

The classic Top 10 list.
The huge Top 100 list.
Sites ranked by the total number of diggs received on all stories submitted in the last 7 days.
Click the “Popular stories” column heading to rank them by [...]

Continue Reading...

Checking If Page Contains a Link In PHP

September 25th, 2007

Sometimes it is necessary to verify that a page really contains a specific link. This is usually done when checking for a reciprocal link in link exchange scripts.

Continue Reading...

Link Cloaking Plugin Update

September 19th, 2007

Some time ago I created a WordPress plugin that can cloak affiliate links automatically. Today I’m releasing a new version, with all-new feature(s)!
The main improvement I’ve implemented is “static link cloaking”. The previous version of the plugin could only cloak links that you’ve actually used in a post, which is inconvenient if you want to [...]

Continue Reading...

PHP Multithreading – Faking It

August 20th, 2007

PHP doesn’t really support multi-threading per se but there are ways to do “fake” multithreading. Here’s one I saw in the PHPClasses.org newsletter – Multi-thread Simulation.
Note that this class is intedend for use on a webserver, as opposed to running PHP scripts from a command line (or similar). Check the end of this post for [...]

Continue Reading...

How To Force File Download With PHP

August 12th, 2007

Say you want a PHP script that will make the browser to download a file instead of opening it. This is useful for common filetypes that would normally be displayed in a browser, like .html, images, PDFs and .doc files.
You can find a lot of scripts that do this on the web but one thing [...]

Continue Reading...