我有一個問題,試圖讓這個代碼片段爲數組中的每個圖像輸出一個單獨的og:image meta標籤。Facebook元標籤PHP條件
<?php function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
//Defines a default image
$first_img = "http://example.com/images/fbthumb.jpg";
}
return $first_img;
}
?>
目前的代碼返回第一個匹配的IMG SRC標記,但我想這是他們都返回作爲單獨的標籤,所以我可以選擇要使用的共享圖像。
我知道這行:
$first_img = $matches [1] [0];
需要改變成每個條件某種類型的,但林不知道怎麼樣。任何幫助將不勝感激。謝謝!
編輯:
這裏是最後的建議後,我的代碼:
<?php function catch_that_image() {
global $post, $posts;
$result = preg_match_all('#<img.+src=[\'"]([^\'"]+)[^>]*>#i', $post->post_content, $matches);
return $matches[1];
}
>
「/>
我仍然無法數字出來? 。任何想法?
'] *>#i',$ post-> post_content,$ matches); foreach($ matches [1] as $ match){ $ imgSources [] = $ match; } return $ imgSources; } > <元屬性= 「OG:圖像」 CONTENT = 「?」?/>' –
brianr1
2012-04-17 17:43:04