How to change the size of video with php

How to change the size of video with php
Written by Admin

If you use php on your site and share video from Youtube or vimeo, see how you can change their size easily, without changing every single post.

Let's say you have a post and it contains an embed code from Youtube. You will going to pass the post's content into a variable named $post.

Using the preg_replace function we'll change the size of the video.

This way will always keep the videos in one size, which is ideal if you have a lot of posts and you don't want to change them manually.

$post= preg_replace('/(width)=("[^"]*")/i', 'width="600"', $post);
$post= preg_replace('/(height)=("[^"]*")/i', 'height="400"', $post);

About the author



Welcome to my blog. My name is Akis Mparekas. I am a freelance web developer from Greece and I have been involved in SEO, Website Migration (transferring content from a site, eg blogger to WordPress), website optimization, and web scraping (extracting content from one or more sites) for years.

At the same time I am taking my first steps in game development (unity) and animation (blender). I also create cool stuff, either for work or for fun. When I have time, I write tutorials and I blog.

Leave a Comment