Hudzilla.org - the homepage of Paul Hudson
Contents > Functions Wish List | Report Bug | About Me ]

4.7     Playing with strings

This is NOT the latest copy of this book; click here for the latest version.

Learning how to manipulate text strings is one of the more rewarding things to learn in PHP - there are many helpful functions in the language that you can make quick and easy use of that allow you to do all sorts of crazy things with user input.

In this section we will be starting off with a few key functions you are likely to be using regularly, but we will also be discussing some of the more niche functions that are just as useful. I have sorted these functions by their usefulness - if you only have a short time to read this book for some reason (you know, if you keep reading a page every time you visit your book store, you will need about three years!) you should learn the functions in order.

As with variables name PHP considers strings to be case sensitive, which means matching and replacing strings would be quite tricky if it were not for the fact that PHP provides case-insensitive versions of each function where it would be helpful. These are mentioned wherever they occur.

Once the basic matching functions are out of the way, we will be moving onto a tricky topic - regular expressions. Regular expressions, or regexps as they are more commonly known, are hard to learn, but provide an incredibly fast and flexible way to manipulate strings.

You will almost certainly be doing a lot of work with strings at some point, so it is strongly recommended that you read the whole of this section thoroughly, and try each of the examples yourself - remember, much programming, much power!





<< 4.6.6 Mathematical constants   4.7.1 Reading from part of a string: substr() >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
Be the first to add a comment to this chapter!



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is four plus three?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow