Кто-нибудь знает regexp, чтобы извлечь только идентификатор видео из <embed>
Vimeo <embed>
используя php?
например:
13084859
из:
<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>
Вот:
$html = '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>'; if (preg_match('/moogaloop\.swf\?clip_id=([0-9]+)/', $html, $matches)) { echo $matches[1]; } else { echo 'n/a'; }
Вот простая функция, которую я написал для вас, прекрасно работает, но не использует regex 🙂
<?php function get_vimeo_id( $embed ) { $vimeo_id_array = explode( '?clip_id=', $embed ); $vimeo_id_array_2 = explode( '&', $vimeo_id_array[1] ); $vimeo_id = $vimeo_id_array_2[0]; return $vimeo_id; } // Get Vimeo Id $vimeo_id = get_vimeo_id( '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=13084859&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>' ); // Use $vimeo_id echo $vimeo_id; ?>