How to find all the substrings between two delimiters in PHP?


For example, assume there is a string

"var name=cat; *bunch of random strings* var name=dog; *bunch of random strings* var name=cow; *bunch of random strings*"

I want to parse this string and find all the strings between the two delimiters, "name=" and ";". So, I want to extract the words cat, dog, and cow and put them in an array. Any idea how I should do this?

I don't know that explode does the trick, but this seems to:

$string = "var name=cat; *bunch of random strings* var name=dog;*bunch of random strings*var name=cow;*bunch of random strings*";
preg_match_all('/name=([^;]+)/', $string, $matches);

or, as a function :

function wizbangStringParser ($string) {
    preg_match_all('/name=([^;]+)/', $string, $matches);
    return $matches[1];