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
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

Edited by drisate
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.