如何使用param查找对象标记,并使用简单的html DOM php在HTML中嵌入标记
I found it really hard for me to understand the simple html dom of php. Even if I read the instruction on how to do it. As for me, I'm just new in programming industry. As I've been searching on how to find the object tag and embed, I can't find the right answer. So in here , I will post my problem and hoping for the right answer. :)
I can't find the object of this: http://vodlocker.com/embed-gu09418zgs6y.html
and here is the object tag with param from the page source of the vodlocker. and this is what i want to get.
<object type="application/x-shockwave-flash" data="http://vodlocker.com/player/player.swf" width="100%" height="100%" bgcolor="#000000" id="flvplayer" name="flvplayer" tabindex="0" __idm_id__="937985">
<param name="allowfullscreen" value="true"><param name="allowscriptaccess" value="always">
<param name="seamlesstabbing" value="true">
<param name="wmode" value="opaque"><param name="flashvars" value="netstreambasepath=http%3A%2F%2Fvodlocker.com%2Fembed-gu09418zgs6y.html&id=flvplayer&file=http%3A%2F%2F95.211.193.83%3A8777%2Fk6ceg4duoo4pcnokaktshz6a5e6vcg4hy7lzvwxjtd7dcwtb4o6vtdk5fe%2Fv.mp4&provider=http&image=http%3A%2F%2F95.211.193.83%3A8777%2Fi%2F02%2F00142%2Falirtn87xlws.jpg&skin=http%3A%2F%2Fvodlocker.com%2Fplayer%2Fmodieus1.zip&duration=12126&plugins=timeslidertooltipplugin-3h%2Chttp%3A%2F%2Flp.longtailvideo.com%2F5%2Fsharing%2Fsharing.swf&allowfullscreen=always&wmode=opaque&allowscriptaccess=always&stretching=uniform&abouttext=vodLocker&aboutlink=http%3A%2F%2FvodLocker.com&timeslidertooltipplugin.preview=%5B%5BJSON%5D%5D%7B%22enabled%22%3Atrue%2C%22path%22%3A%22http%3A%2F%2F95.211.193.83%3A8777%2Fi%2F02%2F00142%2F%22%2C%22prefix%22%3A%22alirtn87xlws%22%2C%22frequency%22%3A%22485%22%7D&timeslidertooltipplugin.pluginmode=HYBRID&sharing.sharing.link=&sharing.sharing.code=%253CIFRAME%2520SRC%253D%2522http%253A%252F%252Fvodlocker.com%252Fembed-gu09418zgs6y-720x400.html%2522%2520FRAMEBORDER%253D0%2520MARGINWIDTH%253D0%2520MARGINHEIGHT%253D0%2520SCROLLING%253DNO%2520WIDTH%253D720%2520HEIGHT%253D%253E%253C%252FIFRAME%253E&sharing.link=http%3A%2F%2Fvodlocker.com%2Fgu09418zgs6y&sharing.code=%253CIFRAME%2520SRC%253D%2522http%253A%252F%252Fvodlocker.com%252Fembed-gu09418zgs6y-640x360.html%2522%2520FRAMEBORDER%253D0%2520MARGINWIDTH%253D0%2520MARGINHEIGHT%253D0%2520SCROLLING%253DNO%2520WIDTH%253D640%2520HEIGHT%253D360%253E%253C%252FIFRAME%253E&sharing.pluginmode=HYBRID&controlbar.position=over&dock.position=left&logo.file=http%3A%2F%2Fvodlocker.com%2Fimages%2Fvodjw_logo.png&logo.hide=false&logo.timeout=10&logo.over=1&logo.out=0.8&logo.position=top-right&logo.link=http%3A%2F%2FVodlocker.com">
</object>
Here's my code. which is not working. i dont know why. also on other sites that contains embed. it is also not working.
include "include/simple_html_dom.php";
$a = "http://vodlocker.com/embed-gu09418zgs6y.html";
$html = file_get_html($a);
$b = $html->find('object')[0];
echo $b;
Two problems, it looks like. First off, I believe what you want is:
$b = $html->find('object', 0);
Per the docs, this is how to find the first instance of the <object>
tag.
Your second problem, though, is that the $html does not return any code with <object>
tags - the code block you're searching for is not there.
If what you're looking for is the http://95.211.193.83:8777/k6ceg4duoo4pcnokaktshz6a5e6vcg4hy7lzvwxjtd7ddxdeooarqi7uci/v.mp4
value, it's embedded in the <script>
tags in the header, so try:
$b = $html->find('script');
Then loop through the array that $b
returns until you get what you're looking for.
I think your problem is $b = $html->find('object')[0];
. Although that works in many languages it won't work on PHP versions below 5.4. Do this instead:
$b = $html->find('object'); $b = $b[0];
Personally I use DOMDocument:
$dom = new DOMDocument;
@$dom->loadHTMLFile('http://vodlocker.com/embed-gu09418zgs6y.html');
if($objs = $dom->getElementsByTagName('object')){
foreach($objs as $o){
// $o is each <object> $objectHTML[] = $dom->saveHTML($o);
foreach($o->childNodes as $p){
if(preg_match('/^param$/i', $p->nodeName)){
// $p is each <param> in loop
}
}
}
}
Where I have commented out $objectHTML[] = $dom->saveHTML($o);
, the $objectHTML
Array would contain each Object as HTML. $objectHTML[0]
would be the first object tag and its contents as HTML.