PHP:将视频标记添加到youtube链接fron内容

时间:2015-07-02 08:40:18

标签: post youtube preg-replace

我有变量$post->post_content,可以返回YouTube上的帖子和视频网址的详细信息。

我需要从$post->post_content其他YouTube链接中删除任何文字,并添加到YouTube likn此标记

<video>YouTube_URL</video>

content喜欢: -

At this instant, while Daggoo, on the summit of the head, was clearing the whip—which had somehow got foul of the great cutting tackles—a sharp cracking noise was heard; and to the unspeakable horror of all, one of the two enormous hooks suspending the head tore out, and with a vast vibration the enormous mass sideways swung, till the drunk ship reeled and shook as if smitten by an iceberg. The one remaining hook, upon which the entire strain now depended, seemed every instant to be on the point of giving way; an event still more likely from the violent motions of the head.

https://www.youtube.com/watch?v=JEreM0ZKY18

还有一段时间: -

أسر شعار اسبوعين الدولارات من, شرسة أعلنت اندلاع إذ هذا. وبعد الثالث أوكيناوا ما بين, الحصار الأمامية بـ عدد. ذات بقعة فمرّ إذ, أخذ كل بالحرب وسمّيت المانيا. و فصل بمباركة المقيتة, أملاً الحصار المتاخمة من عدد. بزمام أثره، التبرعات تم بعد, الجيش خصوصا كانتا ان دار.

    https://www.youtube.com/watch?v=JEreM0ZKY18

我的代码:

$posts = query_posts('showposts='.$numposts.'&cat=19');
foreach ($posts as $post) { 
$postOutput1 = preg_replace('#<a[^>]+>([\r\n|\n]+)?<img[^>]+>([\r\n|\n]+)?<\/a>#','', $post->post_content);
$postOutput2 = preg_replace('@https?://(www\.)?youtube.com/.[^\s.,"\']+@i','', $postOutput1);
$postOutput = preg_replace('[youtube','', $postOutput2);
preg_match_all('@https?://(www\.)?youtube.com/.[^\s.,"\']+@i', $post->post_content, $matches);
foreach($matches as $match){
    echo "<video>$match</video>";
}}

怎么做呢?

1 个答案:

答案 0 :(得分:0)

试试这个:

$string = "At this instan ... https://www.youtube.com/watch?v=JEreM0ZKY18"
$pattern = '/(http\S*)/im';
$array = array();
preg_match($pattern, $string, $array);
$link = $array[0];
print $link;
相关问题