所以,我基本上是在尝试匹配对象标签内(包括)的任何内容,如下所示:
<?php preg_match_all('/<object(.*)<\/object>/', $blah, $blahBlah); ?>
它为此找到匹配项:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="250" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=9048799&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="250" src="http://vimeo.com/moogaloop.swf?clip_id=9048799&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object>
但它不会匹配这个:
<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5630744&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=00ADEF&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5630744&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=00ADEF&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
知道为什么吗?感谢您的任何见解。
ETA:由于我的方法一开始可能有问题,这里有一些关于我正在尝试做的事情的背景。
这是一个 Wordpress 网站。我正在使用一个将短标签转换为完整视频嵌入代码的插件。该插件最近(谢天谢地)更新以使代码更有效。
我正在尝试创建的功能只是在帖子中找到第一个视频对象,然后将其抓取以在网站的其他地方使用。
这是整个函数(其中一些只有在您使用过 Wordpress 时才有意义):
<?php
function catch_that_video() {
global $post, $posts;
$the_video = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<object(.*)<\/object>/', $post->post_content, $vid_matches);
$the_video = $vid_matches [1] [0];
if(empty($the_video)){ $the_video = 0; }
return $the_video;
}
?>