string
PHP Random String Function
Fri, 01/28/2011 - 12:37 | by philipnorton42I 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.
Count Number Of Characters In A String With MySQL
Thu, 09/30/2010 - 17:00 | by philipnorton42Today I needed to grab some data from a table where there was more than one occurrence of a string within another string. Basically, I needed to find all URL's from a table that were more than 3 levels deep (i.e. with 3 slashes), but realised there wasn't a function to do this in MySQL. I found an alternative method, but it got me thinking on how that might be possible.
PHP Paragraph Regular Expression
Wed, 06/09/2010 - 13:13 | by philipnorton42I 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.
Format A List Of Items In PHP
Fri, 01/08/2010 - 11:52 | by philipnorton42It 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.
Using list() With explode() In PHP
Tue, 09/08/2009 - 20:42 | by philipnorton42A simple way to convert a string into a set of variables is through the use of the explode() and list() functions. list() is a language construct (not really a function) that will convert an array into a list of variables. For example, to convert a simple array into a set of variables do the following:
Extract Keywords From A Text String With PHP
Wed, 07/29/2009 - 08:27 | by philipnorton42A 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.