I have a script that pulls YouTube video thumbnails from a playlist, when you hover over them the video title is displayed, I’d like to remove the first 24 characters that display in the title tag automatically each time? How do I do this? Does this need to be done with regex, if so, how?
The PHP code I have setup is:
<?php get_playlists(); ?>
<?php
function get_playlists(){
$data = file_get_contents("http://gdata.youtube.com/feeds/api/playlists/C82EBDAC0429B6A2? orderby=published&max-results=12");
$xml = simplexml_load_string($data);
foreach($xml->entry as $playlist){
$media = $playlist->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[1]->attributes();
$thumb = $attrs['url'];
$attrs = $media->group->player->attributes();
$video = $attrs['url'];
$title = $media->group->title;
$url = $video;
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$vid_Id = $my_array_of_vars['v'];
$thumbnail .= '<div style="float:left; cursor:pointer;">
<p class="crop"><a class="videobox various iframe" href="http://www.youtube.com/embed/' . $vid_Id . '?autoplay=1&hd=1"><img src="' .$thumb . '" title="' . $title . '" width="74" height="56"/></a></p></div>';
}
print $thumbnail;
}
?>
You just need to use
substr()on the value, by changing this:To this:
Note that the value is 23, not 24, since the 0th character index is actually the first character.