如何从像这样的字符串中解析flash变量?
<script type="text/javascript">
flashvars.added = "2010-07-18";
flashvars.name = "testing+purposes";
flashvars.user = "jhon+doe";
</script>
我使用curl来获取字符串。
答案 0 :(得分:2)
可能不完美,但至少应该让你开始:
$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);
可能效率更高,但应该再次帮助您入门。
答案 1 :(得分:0)
将问题中的字符串指定为$ xml:
$dom = new DOMDocument();
$dom->loadXML($xml);
$arr = parse_ini_string($dom->textContent);
print_r($arr);
输出:
Array (
[flashvars.added] => 2010-07-18
[flashvars.name] => testing+purposes
[flashvars.user] => jhon+doe
)