Setting String Character Limit PHP -


i creating vine script, , trying collect thumbnail .jpg selected vine video url set script seen below how it's called on og:image:secure_url

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

what need with

setting string limit of 147 characters. because when thumbs generated vine video url appear this..

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 not read right if contains characters listed

?versionid=i7r_pcp2p1noaplmoi0qgrtvsd8ii43f

my code put string limit in

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;  // see below, made attempt doesn't work.                                      substr(0, 147, $vine, $matches);  } 

your substr() syntax incorrect.

it should be:

substr ($string, $start, $length) 

to use substr(), you'll need store thumbnail url in variable, so:

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; } 

it might idea check if $thumb set before trying use substr():

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

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -