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
);
}
$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>
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']);
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 ;
}
Code Example |
---|
Php :: redirect stderr from echo |
Php :: wp_cache_get |
Php :: laravel validation double |
Php :: laravel activity log package |
Php :: check date PHP |
Php :: new session php |
Php :: wp reserved image size names |
Php :: increase php_values |
Php :: explode example in php |
Php :: laravel create model controller and migration on line |
Php :: php write to standard out |
Php :: include in php |
Php :: phpmyadmin centos 8 |
Php :: laravel mail send flexible subject |
Php :: date hour php |
Php :: php array viewer |
Php :: php error check |
Php :: php clean user input |
Php :: php mod |
Php :: install laravel on windows |
Php :: install php pdo mysql PHP5.6 alpine-apache |
Php :: Laravel 8 Pagination Ui Problem |
Php :: how condition for multiple row by orwhere laravel |
Php :: laravel local scope |
Php :: laravel get data in pivot table |
Php :: get data from another table laravel |
Php :: php check if string is integer |
Php :: php strom key 1 |
Php :: job with queue name in laravel |
Php :: php html to pdf |