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 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 :: copy php array to javascript 
Php :: php while loop array 
Php :: composer create-project laravel/laravel --prefer-dist laravel-bootstrap 
Php :: woocommerce if it is shop page remove breadcrumbs 
Php :: php write file 
Php :: exclude methods in resource route laravel 
Php :: formdata jquery ajax php 
Php :: remove % sign from string php 
Php :: copy env example to .env in laravel 
Php :: php force image refresh 
Php :: php array formatted output 
Php :: php datetime to timestamp 
Php :: php current date get 
Php :: what is forelse in laravel 
Php :: php artisan cache 
Php :: laravel 8 $request-intersect not working 
Php :: laravel $loop interation 
Php :: how to override default name for apiresourc route in laravel 
Php :: proper permission webserver laravel 
Php :: serialize() php 
Php :: how count the rout in route.php laravel 
Php :: woocommerce add custom field data to cart page 
Php :: floor ceil php 
Php :: include and require in php 
Php :: composer cache clean 
Php :: convert string to lowercase in php 
Php :: clear cache via route laravel 
Php :: get raw query laravel 
Php :: how to get the current year in php 
Php :: php move_uploaded_file 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =