Home Blog Page 9

Get YouTube video thumbnail using PHP

0
How to get YouTube Video Thumbnail

welcome back to shortlearner.com , in our previous post we learn how to convert YouTube URL to embed URL PHP.in this post we will see how to Get YouTube video thumbnail and use it with PHP
so in the below code we explode the URL and create a link which will show the thumbnail of individual video id and use it on img tag.

How to get YouTube Video Thumbnail

Also Read :
How to Install PHP on CentOS.
How to integrate Razorpay Payment Gateway using PHP.

Get Domain name from URL
Unable to create a directory a wordpress error
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

<?php
$text = "https://www.youtube.com/watch?v=74WSXAFXoDk";
$video_id = explode("?v=", $text);
$video_id = $video_id[1];
$thumbnail="http://img.youtube.com/vi/".$video_id."/maxresdefault.jpg";
echo "<img src='$thumbnail'>";
?>

Convert a youtube video url to embed code

0
convert youtube url to embed url php

welcome back to shortlearner.com , in our previous post we learn how to Convert words to numbers in PHP. in this post we will see how to Convert a youtube video url to embed code with the help of PHP.
so in the below code we create a PHP function convertYoutube and pass YouTube link as a parameter, the convertYoutube function is converts our URL into embed code.

convert youtube url to embed url php

Also Read :
PHP Login Script With Remember me.
Unable to create a directory a wordpress error
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

<?php
function convertYoutube($string) {
	return preg_replace(
		"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
		"<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/$2\" allowfullscreen></iframe>",
		$string
	);
}
$text = "https://www.youtube.com/watch?v=74WSXAFXoDk";
echo convertYoutube($text); ?>

generate an array with a range using PHP

0
How to generate an array of strings numbers with a specific range

Welcome back to shorltearner.com, we are starting a new series of PHP interview questions for beginners and experienced,so in previous post we learn, Converting words to numbers in PHP
In this post we see how to generate an array with a range taken from a string.

How to generate an array of strings numbers with a specific range

Also Read
Unable to create a directory a wordpress error
PHP program that multiplies corresponding elements of two given lists
PHP program to print out the multiplication table up to 6*6
Write a PHP program to check if the bits of the two given positions of a number are same or not

 <?php
function string_range($str1) 
{
  preg_match_all("/([0-9]{1,2})-?([0-9]{0,2}) ?,?;?/", $str1, $a);
  $x = array ();
  foreach ($a[1] as $k => $v) 
  {
    $x  = array_merge ($x, range ($v, (empty($a[2][$k])?$v:$a[2][$k])));
  }
  return ($x);
}
$test_string = '1-2 18-20 9-14';
print_r(string_range($test_string));
?> 

Output

Array ( [0] => 1 [1] => 2 [2] => 18 [3] => 19 [4] => 20 [5] => 9 [6] => 8 [7] => 7 [8] => 6 [9] => 5 [10] => 4 )

another way to find range between to given numbers with the help of php predefined function range(), see the below example

<?php
$number = range(0,50,10);
print_r ($number);
?>

Output

Array ( [0] => 0 [1] => 10 [2] => 20 [3] => 30 [4] => 40 [5] => 50 )

Converting words to numbers in PHP

0
convert number to words in php

Welcome back to shorltearner.com, we are starting a new series of PHP interview questions for beginners and experienced,so in previous post we learn, Write a PHP program to check if the bits of the two given positions of a number are same or not
In this post we see how to Converting words to numbers in PHP.
Also Read
Unable to create a directory a wordpress error
PHP program that multiplies corresponding elements of two given lists
PHP program to print out the multiplication table up to 6*6

convert number to words in php
<?php
function word_digit($word) {
    $warr = explode(';',$word);
    $result = '';
    foreach($warr as $value){
        switch(trim($value)){
            case 'zero':
                $result .= '0';
                break;
            case 'one':
                $result .= '1';
                break;
            case 'two':
                $result .= '2';
                break;
            case 'three':
                $result .= '3';
                break;
            case 'four':
                $result .= '4';
                break;
            case 'five':
                $result .= '5';
                break;
            case 'six':
                $result .= '6';
                break;
            case 'seven':
                $result .= '7';
                break;
            case 'eight':
                $result .= '8';
                break;
            case 'nine':
                $result .= '9';
                break;    
        }
    }
    return $result;
}

echo word_digit("zero;three;five;six;eight;one")."\n";
echo word_digit("seven;zero;one")."\n";
?>
035681 701

check the bits of the two given positions of a number are same or not

0
mysql interview questions

Welcome back to shorltearner.com, we are starting a new series of PHP interview questions for beginners and experienced,so in previous post we learn, Write a PHP program to print out the multiplication table upto 6*6
In this post we Write a PHP program to check if the bits of the two given positions of a number are same or not.

mysql interview questions

Also Read :
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?
PHP program that multiplies corresponding elements of two given lists

<?php
function test_bit_position($num, $pos1, $pos2) {
   $pos1--;
   $pos2--;
   $bin_num = strrev(decbin($num));
   if ($bin_num[$pos1] == $bin_num[$pos2]) {
     return "true";
   } else {
     return "false";
   }
}
echo test_bit_position(112,5,6)."\n";
?>