Tuesday, 16 August 2016

Removing black borders on youtube thumbnails

YouTube offers images that don't have the 4:3 ratio black strips. To get a 16:9 video thumbnail with no black strips, try one of these:


http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg



For other YouTube thumbnail option you can use following.


https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

==================

Get Video ID in WordPress

$video_link = get_field('youtube_video',get_the_ID()); 

if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_link, $match)){
    $video_id = $match[1];
}

Thursday, 11 August 2016

Split text string of Full name into $first and $last name in php


$string = "This is test by viral";
//$string = "This";
//$string = "This is ";

$string = trim($string);

The simplest way is, by using explode:
$parts = explode(" ", $string);



After you have the parts, pop the last one as $lastname:
$lastname = array_pop($parts);

Finally, implode back the rest of the array as your $firstname:
$firstname = implode(" ", $parts);


echo '<hr/>';
echo '<strong>First name</strong> :'.$firstname;
echo '<hr/>';
echo '<strong>Last name</strong> :'.$lastname;
echo '<hr/>';