Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[not an issue] Youtube links to Embed player #26

Open
foxnoodles opened this issue Mar 12, 2023 · 0 comments
Open

[not an issue] Youtube links to Embed player #26

foxnoodles opened this issue Mar 12, 2023 · 0 comments

Comments

@foxnoodles
Copy link

Here's a small function that will convert youtube links in your post to embed youtube player. I was too lazy to modify the autolink function because it's not documented properly. So I just wrapped this function with it inside the template. Feel free to add it to the next update @oelna

function youtube($string,$autoplay=0,$width=480,$height=390)
{
    preg_match('#(?:https://)?(?:www\.)?(?:youtube\.com/(?:v/|watch\?v=)|youtu\.be/)([\w-]+)(?:\S+)?#', $string, $match);
    if(isset($match[1])) {
    $embed =  '<iframe title="YouTube video player" width="100%" height="350" src="http://www.youtube.com/embed/'.$match[1].'?autoplay=$autoplay" frameborder="0" allowfullscreen></iframe>';
    return str_replace($match[0], $embed, $string);
    }
    else return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant