2013-10-07 41 views
0

我創建一個藤腳本,我想從下面看到我的腳本設置所選藤視頻網址收集縮略圖.jpg是怎麼這就是所謂的對我的og:image:secure_url設置字符串的字符數限制PHP

<meta property="og:image:secure_url" content="{php} echo vine_pic($this->_tpl_vars['p']['youtube_key']);{/php}" />

我需要

設置的147字符string limit幫助什麼。因爲當拇指從藤視頻URL生成它們出現這樣的..

https://v.cdn.vine.co/r/thumbs/6A6EB338-0961-4382-9D0D-E58CC705C8D5-2536-00000172EBB64B1B_1f3e673a8d2.1.3.mp4.jpg?versionId=i7r_pcP2P1noapLmoI0QgrtvsD8ii43f 

og:image:secure_url所列

?versionId=i7r_pcP2P1noapLmoI0QgrtvsD8ii43f

我的代碼不會向右讀,如果它包含多餘的字符放在

function vine_pic($id) 
{ 

$vine = file_get_contents("http://vine.co/v/{$id}"); 

preg_match('/property="og:image" content="(.*?)"/', $vine, $matches); 

return ($matches[1]) ? $matches[1] : false; 

// As you see below, I made an attempt but it doesn't work.          
substr(0, 147, $vine, $matches); 

} 
+0

你的樂趣:檢查是否$thumb試圖使用substr()之前設置在可以調用substr()之前,ction總是返回。 – Kontrollfreak

回答

4

你字符串限制3210語法不正確。

它實際上應該是:

substr ($string, $start, $length) 

要使用substr(),你需要的縮略圖URL存儲在一個變量,像這樣:

function vine_pic($id) 
{ 
    $vine = file_get_contents("http://vine.co/v/{$id}"); 
    preg_match('/property="og:image" content="(.*?)"/', $vine, $matches); 
    $thumb = ($matches[1]) ? $matches[1] : false; 
    $thumb = substr($thumb, 0, 147); 
    return $thumb; 
} 

這可能是一個好主意

if ($thumb) { 
    $thumb = substr($thumb, 0, 147); 
    return $thumb; 
} 
+0

你是一個拯救生命的人。謝謝你:3 – Nelson

+0

@Nelson:不客氣:) –