How can I parse the flash vars from a string like this?
<script type="text/javascript">
flashvars.added = "2010-07-18";
flashvars.name = "testing+purposes";
flashvars.user = "jhon+doe";
</script>
I am using curl to get the string.
How can I parse the flash vars from a string like this?
<script type="text/javascript">
flashvars.added = "2010-07-18";
flashvars.name = "testing+purposes";
flashvars.user = "jhon+doe";
</script>
I am using curl to get the string.
May not be perfect, but should at least get you started:
$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];
}
}
var_dump($flashVars);
Probably could be more efficient, but again should help you get started.
Given the string in the question as $xml:
$dom = new DOMDocument();
$dom->loadXML($xml);
$arr = parse_ini_string($dom->textContent);
print_r($arr);
Output:
Array (
[flashvars.added] => 2010-07-18
[flashvars.name] => testing+purposes
[flashvars.user] => jhon+doe
)