将YouTube嵌入代码剥离为仅URL [英] Strip YouTube Embed Code Down to URL Only

查看:88
本文介绍了将YouTube嵌入代码剥离为仅URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助!

我需要剥离以下代码,使其仅使用值部分

I need to strip the following code so that it only uses the "value" part

$<object width="360" height="226"><param name="movie" value="http://www.youtube.com/v/IkZuQ-aTIs0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/IkZuQ-aTIs0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="226"></embed></object>

因此,在这种情况下,它会将其剥离为 http://www.youtube.com/v/IkZuQ-aTIs0

So in this case it would strip it down to http://www.youtube.com/v/IkZuQ-aTIs0

问题是这是动态的,因此它会为不同文件提取这些嵌入代码,因此它们正在更改。

The catch is that this is dynamic so it is pulling these embed codes for different files so they are changing.

请帮助:D

推荐答案

<?php

$string = '<object width="360" height="226"><param name="movie" value="http://www.youtube.com/v/IkZuQ-aTIs0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/IkZuQ-aTIs0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="360" height="226"></embed></object>';

preg_match_all('#http://www.youtube.com/v/([\w\-]+){11}#is', $string, $matches);

print_r( array_unique($matches[0]) );

?>

这篇关于将YouTube嵌入代码剥离为仅URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆