Since you really want options, a JS object, here is a deathstar-sized overkill solution to parse such things natively. Idea here is to extract the part you want, housed between the { } JSON object in JS, and then evaluate it into a usable structure with PHP's json_decode. In this code, I stored the HTML fragment into $variable0.
// expression broken down for readability
$frag = array(
"/<script>",
".*?", # whitespace
"uploadify\(",
"(.*?)", # our desired match
"\);", # closest )
"(.*)", # more whitespace we don't want
"<\/script>/s"
);
// flatten expression into match string
$expr = implode("", $frag );
So at this point, $expr is /<script>.*?uploadify\((.*?)\);(.*)<\/script>/s
$m = preg_match( $expr, $variable0, $r );
Now $r should be an array, of which $r[1] contains that "{... }" snippet. This can be evaluated with json_decode, however, the string is malformed for json_decode to use. For one, the keys have to be enclosed in quotes (ie: uploader: '' should be 'uploader': '') in javascript. Literally, $r[1] looks like this:
{
uploader : '/uploadify/uploadify.php',
}
Another person came up with a cleaning function that we can apply here.
// fix thanks to http://stackoverflow.com/a/14075951/415324
function fix_json( $a ) {
$a = preg_replace('/(,|\{)[ \t\n]*(\w+)[ ]*:[ ]*/','$1"$2":',$a);
$a = preg_replace(
'/":\'?([^\[\]\{\}]*?)\'?[ \n\t]*(,"|\}$|\]$|\}\]|\]\}|\}|\])/','":"$1"$2',
$a);
return( $a );
}
// $r[1] will contain innards of uploadify(), which is JSON
$json = fix_json( $r[1] );
This turns $json into something that PHP can parse natively. $json now looks like:
{"uploader":"/uploadify/uploadify.php',"}
Note that there is a trailing comma up there. That's a javascript error in the original HTML you're extracting, and it needs to be fixed on the site. More on that below.
$options = json_decode( $json );
And at this point, we have a object we can use in PHP
var_dump( $options );
object(stdClass)#2 (1) {
["uploader"]=>
string(24) "/uploadify/uploadify.php"
}
Thus, you can easily access any additional options you encounter, with echo $options->uploader;
NOTE: There is a problem with original HTML --- it contains a trailing comma that breaks javascript parsing in some browsers. Think FireFox will cut it some slack, but certainly not IE. To fix the JS, remove the trailing comma in the options object:
$("#file_upload_1").uploadify({
uploader : '/uploadify/uploadify.php'
});