2010-06-01 37 views
0

如何在HTML頁面上匹配並獲取flash vars?我使用簡單的HTML DOM元素,我可以縮小到包含我需要的文本的div。使用簡單的HTML Dom匹配頁面上的字符串

<script type="text/javascript"> 
var s1 = new SWFObject("jw4.4/player.swf", "player", "400", "50", "9"); 
s1.addParam("allowfullscreen", "true"); 
s1.addParam('allowscriptaccess','always'); 
s1.addVariable("width","400"); 
s1.addVariable("height","50");  
s1.addVariable("overstretch", "false"); 
s1.addParam('flashvars',"this_id=/tg&amp;autostart=true");  
s1.write("container"); 

我如何獲得的this_id的價值,所以我想回到/tg?我會發現什麼?還是我必須使用別的東西?

$html = file_get_html("$url"); 

$file_path = $html->find('this_id=/'); 

感謝所有的幫助

回答

1

我認爲是用正則表達式來實現更好 - simpledom會讓你找到(「PARAM」);而不是你必須遍歷結果尋找strpos($ elem-> flashvar,'this_id = /')!== false的結果。

正則表達式將是/ this_id = /([^ &] +?)&/

+0

如果一些的id包含'&'。是否可以這樣做:'/ this_id = \ /([^&] +?)&amp;'以確保它停在'&amp; - 我的正則表達式不是技能不是很好,你會用它的preg_match? – Abs 2010-06-01 16:32:51

+0

你的正則表達式可以工作,如果我添加'&amp'位,它也可以工作。 – Abs 2010-06-01 16:41:06

+0

哥們沒問題;) – Tobias 2010-06-03 01:30:41