Q:

Get a string out of a string? Explode?

I have the following string
<embed src='herp.com'  width='240' height='180'  allowscriptaccess='always' allowfullscreen='true' flashvars='volume=94&stretching=fill&file=http%3A%2F%2Fmedia.cdn.com%2FTHEMP%2Fflash%2Ffile.mp4&plugins=viral-1d'/>

And I want to get the http%3A%2F%2Fmedia.cdn.com%2FTHEMP%2Fflash%2Ffile.mp4&plugins=viral-1d out of it.
I was thinking explode by = and then grab the second last value, but this may be error prone (example if they add another herp="blah" after the flashvars variable the script would no longer work), is there any other way that is a little more bulletproof to syntax changes around the string I need?

A:

The proper method here is to parse the HTML with a proper HTML parsing library and extract the flashvars attribute from the <embed> tag. If you have only one of these though, you really can just use a regular expression.  
The expression will retrieve the flashvars attribute, and that value is passed to parse_str() to retrieve all the query string components.  parse_str() will call urldecode() on them so you don't need to.
// Regex gets the entire flahsvars
$pattern = "/<embed[^>]+flashvars='([^']+)'/";
preg_match($pattern, $embed, $matches);

// $matches[1] now holds the full contents of `flashvars`

// Then parse_str() on the result:
$parts = array();
parse_str($matches[1], $parts);
print_r($parts);

// The part you want is in the file key:
echo $parts['file'];

Array
(
    [volume] => 94
    [stretching] => fill
    [file] => http://media.cdn.com/THEMP/flash/file.mp4
    [plugins] => viral-1d
)

An explanation of the regular expression used:
/<embed[^>]+flashvars='([^']+)'/

It first looks for <embed followed by any character except the closing > ([^>]+).  The capture group following flashvars= will look for all characters up to but not including the closing quote on the flashvars attribute and store them in the first capture group $matches[1].

