PHP Logo

Display A Dynamicly Highlighted String With PHP

7th February 2011 - 4 minutes read time

This function might be of limited use, but it can create some neat effects in your titles. It works by splitting a string into little bits using the spaces and then puts it back together again into two sections. The first section will be normal, but the second section will be wrapped in a span element. By using this function you can create an interesting effects in your titles by styling the first half differently from the second.

PHP Logo

Extract Keywords From A Text String With PHP

29th July 2009 - 5 minutes read time

A common issue I have come across in the past is that I have a CMS system, or an old copy of Wordpress, and I need to create a set of keywords to be used in the meta keywords field. To solve this I put together a simple function that runs through a string and picks out the most commonly used words in that list as an array. This is currently set to be 10, but you can change that quite easily.

The first thing the function defines is a list of "stop" words. This is a list of words that occur quite a bit in English text and would therefore interfere with the outcome of the function. The function also uses a variant of the slug function to remove any odd characters that might be in the text.