Jump to content

Capture flashvars


drisate

Recommended Posts

Hey guys i need to capture the flash vars located in the middle of a string that contains the HTML of an external page.

 

The string to capture looks like this:

 

[...]

var flashvars = {
    'file' : 'http://***pods/lawandsociety/P130631MLJMuñiz-Fraticelli.mp3'
    'width' : '492',
    'height' : '60',
    'controlbar' : 'bottom',
    'dock' : 'false',
    'icons' : 'false',
    'logo.hide' : 'false',
    'logo.position' : 'bottom-left',
    'playlist' : 'none',
    'skin' : 'http://***/wp-content/plugins/flash-video-player/skins/overlay/overlay.swf'
    'autostart' : 'false',
    'bufferlength' : '1',
    'item' : '0',
    'mute' : 'false',
    'repeat' : 'none',
    'shuffle' : 'false',
    'smoothing' : 'true',
    'stretching' : 'uniform',
    'volume' : '90'
};

[...]

 

I need it to be converted into $flashvars[file]

Link to comment
https://forums.phpfreaks.com/topic/282364-capture-flashvars/
Share on other sites

This is what i got so fare:

 

            $script = file_get_contents($link);
            $matches = array();
            preg_match_all('~flashvars\.([a-z]+) .*=.*"(.*)";~i', $script, $matches);
            
            if (!empty($matches[1])) {
                $flashVars = array();
                foreach ($matches[1] as $index => $key) {
                    $flashVars[$key] = $matches[2][$index];
                }
            }

 

All i need is a valide regex

Link to comment
https://forums.phpfreaks.com/topic/282364-capture-flashvars/#findComment-1450702
Share on other sites

regex isn't really good for trying to parse code. Having said that, you're going to have to make some assumptions and hope for the best no matter how you slice this, short of running the page through something that can properly render the javascript.

 

But here's my take:

 

preg_match('~var flashvars\s*=\s*(\{.*?\});~s',$content,$flashvars);
$flashvars = str_replace("'",'"',utf8_encode($flashvars[1]));
$flashvars = array_map('utf8_decode',json_decode($flashvars,true));
This should (again, taking some liberties and hoping for the best), convert it into a php associative array.

 

Array
(
    [file] => http://***pods/lawandsociety/P130631MLJMuñiz-Fraticelli.mp3
    [width] => 492
    [height] => 60
    [controlbar] => bottom
    [dock] => false
    [icons] => false
    [logo.hide] => false
    [logo.position] => bottom-left
    [playlist] => none
    [skin] => http://***/wp-content/plugins/flash-video-player/skins/overlay/overlay.swf
    [autostart] => false
    [bufferlength] => 1
    [item] => 0
    [mute] => false
    [repeat] => none
    [shuffle] => false
    [smoothing] => true
    [stretching] => uniform
    [volume] => 90
)
Link to comment
https://forums.phpfreaks.com/topic/282364-capture-flashvars/#findComment-1450730
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.