Replace YouTube and Vimeo embeds with their poster images

Given some html I want a php function to find all youtube and vimeo videos contained with [embed] tags and replace them with the their corresponding poster images.

To this point I have created some code but I can't work out a few issues see below.

The problems that I am having are:

- If [embed] tags are on one line the first preg_replace works but overwrites the others

- Also I can't work out how to get the poster image for vimeo videos

If you paste this code into phpfiddle and run it you will see what I mean

$embeds_on_1_line = '[embed][url removed, login to view][/embed] [embed][url removed, login to view][/embed] [embed][url removed, login to view][/embed]<br><h2>ABOVE see - Embeds on one line doesn\'t work Vimeo videos missing</h2>';

$html1= replace_sc_with_images($embeds_on_1_line);

echo $html1;

$embeds_on_multi_line = '[embed][url removed, login to view][/embed]

[embed][url removed, login to view][/embed]

[embed][url removed, login to view][/embed]<br><h2>Multi line works</h2>';

$html2= replace_sc_with_images($embeds_on_multi_line);

echo $html2;

function replace_sc_with_images($html) {

$temp_vimeo_image = '[url removed, login to view]';

$html_back = '';

//replace youtube

$html_back = preg_replace('#\[embed\]((?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=))([\w-]{10,12}))(.*)?\[\/embed\]#', '<a href="$1"><img src="[url removed, login to view]$2/[url removed, login to view]"></a>', $html);

//replace vimeo

$html_back = preg_replace('#\[embed\](https?:\/\/(?:www\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11}))\[\/embed\]#', '<a href="$1"><img src="'.$temp_vimeo_image.'"></a>', $html_back);

return $html_back;


Beceriler: PHP, Regular Expressions

Daha fazlasını gör: vimeo com, print w 9, how to get youtube, how to get on youtube youtube, vimeo youtube, watermark vimeo youtube, family tree poster images, playlist vimeo youtube, greeting year 2011 vimeo youtube, jquery embed vimeo youtube, crufts 2010 poster images, vimeo youtube dailymotion api, video vimeo youtube, nightclub poster images

İşveren Hakkında:
( 31 değerlendirme ) Bendigo, Australia

Proje NO: #10576663


%selectedBids___i_period_sub_7% gün içinde 25%project_currencyDetails_sign_sub_9% %project_currencyDetails_code_sub_10%
(0 Değerlendirme)

Bu iş için 2 freelancer ortalamada $25 teklif veriyor


A proposal has not yet been provided

in %bids___i_period_sub_35% gün içinde25%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(0 Değerlendirme)