Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php convert link to embed youtube

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 src="//www.youtube.com/embed/$2" allowfullscreen></iframe>",
        $string
    );
}
Comment

php replace youtube embed url

$youtubeUrl = 'https://www.youtube.com/watch?v=1cQh1ccqu8M';
$youtubePattern = "/s*[a-zA-Z//:.]*youtu(be.com/watch?v=|.be/)([a-zA-Z0-9-_]+)([a-zA-Z0-9/*-\_?&;\%=.]*)/i";
function youtubeEmbedCallback($matches) {
    if (!isset($matches[2])) {
        return '';
    }
    $videoId = $matches[2];
    return '<iframe width="560" height="315" src="https://www.youtube.com/embed/' . $videoId . '" frameborder="0" allowfullscreen></iframe>';
}
$youtubeEmbed = preg_replace_callback($youtubePattern, "youtubeEmbedCallback", $youtubeUrl);
echo $youtubeEmbed;
//Stamperà:
//<iframe width="560" height="315" src="https://www.youtube.com/embed/1cQh1ccqu8M" frameborder="0" allowfullscreen></iframe>
Comment

php get embed code from youtube url

preg_replace("/s*[a-zA-Z//:.]*youtube.com/watch?v=([a-zA-Z0-9-_]+)([a-zA-Z0-9/*-\_?&;\%=.]*)/i","<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>",$post_details['description']);
Comment

how to convert youtube url to embed code in php

function getYoutubeEmbedUrl($url)
{
     $shortUrlRegex = '/youtu.be/([a-zA-Z0-9_-]+)??/i';
     $longUrlRegex = '/youtube.com/((?:embed)|(?:watch))((?:?v=)|(?:/))([a-zA-Z0-9_-]+)/i';

    if (preg_match($longUrlRegex, $url, $matches)) {
        $youtube_id = $matches[count($matches) - 1];
    }

    if (preg_match($shortUrlRegex, $url, $matches)) {
        $youtube_id = $matches[count($matches) - 1];
    }
    return 'https://www.youtube.com/embed/' . $youtube_id ;
}
Comment

PREVIOUS NEXT
Code Example
Php :: autoload file in laravel 
Php :: php add variable to array 
Php :: group where conditions in laravel 
Php :: how to check if all values in an array are equal php 
Php :: custom autoload without composer 
Php :: laravel database seeder 
Php :: composer install laravel 
Php :: how to trim string in laravel 
Php :: define constructor in trait php 
Php :: php arrow function 
Php :: Installing Maatwebsite excel import export package 
Php :: show one value after point php 
Php :: composer create project 
Php :: laravel app running in console 
Php :: sass mix laravel 
Php :: declare variable in php class 
Php :: how to set up the laravel ssh keygen 
Php :: php null 
Php :: import faker in laravel 
Php :: php add custom button in wordpress editor 
Php :: laravel blade @auth 
Php :: url segment laravel 
Php :: strip non numeric and period php 
Php :: jquery send form data to php 
Php :: string between two strings 
Php :: rewrite url to exclude php extension 
Php :: find php ini 
Php :: php string to date 
Php :: generate fake name php 
Php :: array_merge 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =