One way is to use [man]strpos/man to find the position of the two strings, and then use [man]substr/man to get the portion in between.
Another way is to use [man]preg_match/man, e.g.
if (preg_match('/first(.*)last/', $var, $matches) {
// now use $matches[1]
}