Using Strings In PHP

Strings can be a tricky thing to use in any programming language. Each language has their own built in functions for manipulating them, but once you learn how to change stuff inside a string, it can become one your best friends.

We have already shown you how to define a string. But lets say you wanted to add something to a string. For instance, say we had:

$first_name = “John”;
$last_name = “Doe”;
and we wanted to combine the two variables into one single variable. The easiest way is to just add the $last_name to the $first_name. We do this in the following manner:
1. $full_name = $first_name; 2. $full_name .= “ “ . $last_name;
Did you notice the .= in the second line? That tells PHP to append the value after the equal sign to the current value of the variable.

Below is a list of the most useful functions to use with strings and what they do. Each has their own mini-tutorial to go along with and some examples as to how to use them.