2011-04-28 32 views
2

我有這個現有的代碼不起作用,因爲我想獲取flashvars,itemId值是爲了某種目的而採取的。我如何解析並採取它?如何解析嵌入對象並從此使用PHP獲取flashvars值?

我需要的值爲itemid = 「OWYrYlg5VW9GZUI4UjVnMXFOUGsrQT09」

<?php 
$result = '<embed src=\'http://www.test.com//test_1.swf\' quality="high" FlashVars="itemId=OWYrYlg5VW9GZUI4UjVnMXFOUGsrQT09&autoplay=0&duration=02:45&url=http://test.com" bgcolor="#ffffff" wmode="opaque" width="320" height="65" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>'; 

//preg_match("/\<embed.*itemId\=\"(.+)\".*\>.*\<\/embed\>/Us",$result,$match); 

parse_str($result, $output); 

print '<pre>'; 
print_r ($output); 




?> 
+0

可能重複的具體實施方法,以解析HTML(http://stackoverflow.com/questions/3577641/best- methods-to-parse-html) – 2011-04-28 09:29:03

回答

1
$result = 'your string'; 
$output = ''; 

preg_match('/itemId=([a-zA-Z0-9]+)/', $result, $matches); 
$output = $matches[1]; 
+0

非常感謝你... – logudotcom 2011-04-28 10:20:43

0
preg_match("!<embed.*?itemId=([^&]+).*?>.*?</embed>!sm",$result,$match); 
+0

both are works fine..great,非常感謝你的專家... – logudotcom 2011-04-28 10:21:55