As with many things in PHP, manipulating strings can be handled a number of ways. I often find myself creating a string of items from an array for presentation on screen or entry into a database. I figured now would be a good time to explore the best method of removing that pesky comma that usually ends up at the end of a looped string (which just so happens to be the wrong way of going about it). The proper way

There is certainly no shortage of this topic on the web. Unfortunately for newer developers, there is no way to tell the good advice from the bad. In this article I will show you the wrong way and the right way. See the proper way.

If you need to search for and replace text in a database column, MySQL provides a built in method similar to other scripting languages. Get the syntax.

The following simple code samples will use PHP regular expressions strip away all characters from a string that are not letters or number. Learn the code.

It’s easy to strip non-numbers from a php string. This is common when attempting to format fields like phone numbers or money amounts for entry into a database. Learn the code.

JavaScript has two built in methods that are very similar in name and function- substring() and substr(). Developers and designers who also use server side languages may find it easy to mix them up, since methods like these have similar names across other languages. Either way, mixing them up might cause bugs with your scripts. For example, see the snippet below that looks almost identical, but yields different results.

Here are some cheat sheets for common Javascript string needs. Your choice of built-in methods or regular expressions. View the Code