Example 1

We have a string $name that contains name in the format Last,First we want to break it up so that we have the variable $first and $last. There are several ways to do this.

the first method is to find the position of the comma. Then we can take the substring that is before the comma and call the $last. The substring that is after the comma is $first.

$name="Banks,Robin";
$comma=strpos($name,","); //5
$last=substr($name,0,$comma); //begin in 0 for a length of $comma (5)
echo "Last name = $last<BR>";
$first=substr($name,$comma+1); //after the comma to the end of the string
echo "First name = $first<BR>";
Method 2 will be to use explode to create an array:
$name="Banks,Robin";
$parts=explode(",",$name); //make an array called parts by breaking the string on the comma
$last=$parts[0]; //arrays start with 0
$first=$parts[1];
echo "Hello, $first $last!";
Method 3 starts by making $last a null string (a length of 0) It loops through the string and concatenates one letter at a time to $last until it finds a comma. This method is not very efficient here, but is a useful technique in some more complicated situations.
$name="Banks,Robin";
$last=""; //start with a null string
$i=0;
while(substr($name,$i,1)!=",")){
	$last.=substr($name,$i,0); //concatenate each letter at the end
	$i++;
}
$first=substr($name,$i); //everything after the comma is the first name
echo "Hello $first $last!<BR>";