PHP Strings

Posts about manipulating strings in different ways in PHP

Display A Dynamicly Highlighted String With PHP

Monday, February 7, 2011 - 10:06

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.

Category: 

PHP Random String Function

Friday, January 28, 2011 - 12:37

I was testing a string manipulation function today (which I will post some other time) and I wanted to create a random string of characters that I could feed into it, so I came up with the function below. I thought it was a neat use of the rand() and chr() PHP functions, so here it is.

Category: 

PHP Paragraph Regular Expression

Wednesday, June 9, 2010 - 14:13

I quite often find the need to extract a section of text from the beginning of a blog post or similar to be used as the excerpt. I normally use a function that will count the number of whole words available and return the string containing those words.

A good alternative to this, although only applicable if the original post is in HTML, is to use a regular expression to extract the contents. The following code will take a string and extract just the first paragraph of text.

Category: 

Format A List Of Items In PHP

Friday, January 8, 2010 - 11:52

It is usual when writing a list of items to separate each item with a comma, except the last two items, which are separated with the word "and". I recently needed to implement a function that took a string and converted it into a list of this type so I thought I would expand on it and post it here.

Category: 

Extract Keywords From A Text String With PHP

Wednesday, July 29, 2009 - 09:27

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.

Category: