CancelImage Upload

Topics: PHP String Manipulation Functions
Read our latest entries.
Posted by Garren Harland on September 16, 2009, 9:43 am.
If you are performing a preg_replace on a string it might well be that you do not mean to replace every match within it. Instead you might only want to replace the first item, or a specific number of items.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 5:30 pm.
Although this should usually not happen to an organised programmer, there may come a time with 30'000 plus lines of code, that a track is lost on a certain variable, and that a function is required to check what type of variable once was defined.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 3:51 pm.
When you have thousands and thousands of lines of code it is sometimes hard to tell if a variable has already been set. Of course most programmers will simply check if the string is equal to NULL, but this may not be sufficient all the time. A string can after all have been set, and then later on been given the value of NULL.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 2:14 pm.
As you are no doubt aware speech or quotation marks in the wrong place can cause havoc within a PHP code. The following example for instance will without a doubt produce an error.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 1:27 pm.
To choose between different Content-Types for Russian Cyrillic symbols in PHP we can use the function convert_cyr_string(). This function enables us to switch between the following character sets.
Click here to read on.
Posted by Garren Harland on August 30, 2009, 1:08 pm.
To count the number of appearances of each character within a string we can use the following PHP function.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 2:50 pm.
In a previous tutorial I have discussed the PHP function soundex(), and how it produces a 4 digit code that can be used to compare words that sound alike, but are spelt differently (such as Weather and Whether).
Click here to read on.
Posted by Garren Harland on August 19, 2009, 2:20 pm.
Previously I have discussed how rare symbols can be encoded and decoded from or into ASCII with the PHP functions html_entity_decode and htmlentities(). And while the function htmlentities() is perfect for converting non standard symbols into their ASCII equivalents, it does not convert every symbol out there.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 1:21 pm.
Because of the various symbols that a URL will and might contain, such as colons, slashes, question marks and equals, passing them along as a Get variable is not possible in their original format. Some encoding is needed to make this smooth transition possible.
Click here to read on.
Posted by Garren Harland on August 19, 2009, 12:57 pm.
When passing along a URL as a Get variable, certain symbols need to be converted into a percentage sign, and a two digit hexadecimal equivalent of the corresponding ASCII symbol.
Click here to read on.
Posted by Garren Harland on August 18, 2009, 5:23 pm.
It can happen to anyone. You are looking for one search term, but instead of spelling it correctly you use a word that sounds similar, but is spelt slightly different. For instance you might be searching for the word "Weather" but have accidentally typed the word "Whether".
Click here to read on.
Posted by Garren Harland on August 18, 2009, 4:45 pm.
This tutorial will discuss how you can calculate the similarity of two strings in PHP. The returned value will be the match percentage, ideal therefore for search functions where results only need be displayed with a 50% plus match.
Click here to read on.
Posted by Garren Harland on August 8, 2009, 10:38 am.
Unless you are building a gangster rap forum, chances are that at least 50% of your visitors will not be too impressed by extensive swearing within posts. This however will not stop the other users from continuing to do so.
Click here to read on.
Posted by Garren Harland on August 7, 2009, 8:41 pm.
After you have received date from a textarea, unless you convert the line breaks into
tags, the data entered will all appear in one block. Luckily enough PHP already has a function to solve this problem. No complicated regular expressions are needed to solve this one;-).
Click here to read on.
Posted by Garren Harland on August 5, 2009, 10:28 pm.
On a dynamic website, such as a form, users often get the feeling they can post all kinds of dodgy images to their heart's desire. Now while most webmasters would either A. Let their visitors have their fun, or B. Go nuclear, and ban their visitors from interacting with HTML code, there is another way.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 12:24 pm.
The following function can be of significant value when used with other string manipulation functions. Although it is to be recommended that when outputting special characters in HTML, the ASCII equivalents should be used.
Click here to read on.
Posted by Garren Harland on August 3, 2009, 11:44 am.
If you have a string that can only contains alphanumeric values, it is a lot simpler to state the type of characters that are allowed, instead of looking up every possible symbol on the planet and banning it.
Click here to read on.
Posted by Garren Harland on August 1, 2009, 11:27 am.
A decision every creator of an interactive website faces, is whether or not to allow their visitors to make use of HTML code, or the extent to which they can make use of it. After all, if you give users the option of posting their own HTML messages they might go a bit over the top and post something that does not at all fit in with your layout, or could even cause errors.
Click here to read on.
Posted by Garren Harland on July 31, 2009, 4:38 pm.
As, the title indicates this page will discuss the PHP function split(), and how it can be used in a real world application. We will use an email invite function on a website as an example.
Click here to read on.
Posted by Garren Harland on July 31, 2009, 12:25 pm.
There is a relatively unknown function called parse_url(), which is ideal for evaluating links, and separating them into individual informative components. With the query string section of the URL being one of the more intriguing part. Here is a piece of code that demonstrates how parse_url() works.
Click here to read on.
Posted by Garren Harland on July 28, 2009, 10:59 am.
Dynamically swapping out the ;-), :-), :-( and other smilies shortcuts is as easy as it gets with PHP. All you need to do is perform a simple str_replace(), and in the brackets first specify the shortcut wink, and then after the comma place the image tag and files.
Click here to read on.
Posted by Garren Harland on July 6, 2009, 10:48 am.
The following peace of code can be useful in the following two situations: 1.When a user of your site has reset their password. 2. When a user registers with your site and initially cannot choose their own password. Those are two situations within which this password generator can be used. It produces passwords consisting of random letters and numbers. Any recognisable words would therefore be a coincidence. And indeed meaningless passwords are the most secure type of passwords, when compared to sports teams or wife’s name and date and birth type passwords.
Click here to read on.
Posted by Garren Harland on June 27, 2009, 11:53 am.
When converting and manipulating data, whitespaces play an important role. Especially databases can fill up fields with the required number of empty spaces, which can lead to undesired effects in regard to sort functions. This is why the following three functions are of particular high value.
Click here to read on.
myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com