damnedgentleman Posted May 10, 2011 Share Posted May 10, 2011 Hi there. I'll be honest. I'm totally new to regular expressions and therefore slightly without a clue. I'm attempting to resize default embedded video dimensions so that the video looks better with the layout of my page. Can anyone explain what I'm doing wrong, please? <?php //resize embedded video $find = preg_match("/<iframe(.*)/iframe>/", $eventDescLong, $video); if ($find) { $video = preg_replace('/(width)=("[^"]*")/i', 'width="580"', $video); $video = preg_replace('/(height)=("[^"]*")/i', 'height="387"', $video); } Thanks, Andy Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/ Share on other sites More sharing options...
gizmola Posted May 10, 2011 Share Posted May 10, 2011 Try this simpler regex: '/(width="[^"]+")/i', Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213221 Share on other sites More sharing options...
damnedgentleman Posted May 10, 2011 Author Share Posted May 10, 2011 Try this simpler regex: '/(width="[^"]+")/i', Sadly, that didn't seem to work either. Andy Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213317 Share on other sites More sharing options...
.josh Posted May 10, 2011 Share Posted May 10, 2011 Post the content you are working with ($eventDescLong). Kinda hard to correct or point in the right direction when we don't know the context... Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213371 Share on other sites More sharing options...
damnedgentleman Posted May 10, 2011 Author Share Posted May 10, 2011 Sure. $eventDescLong, is basically the detailed description the an act playing at a live music venue. I'd like to give the venue the opportunity to incorporate embedded video as part of this. It's an underground venue, so we have a lot of acts no-one has heard of playing! The video is basically youtube footage of the acts from other venues, or music videos they have made. This actually works fine atm. It just look a bit ugly as it's out of sync with my page layout which is why I'd like to change the embedded footage size from its default values. However, I'll be honest. I've never really touched regular expressions before. So I don't have a clue! Here's the script that posts the form information to the database. It all seems to work, apart from the video dimension resizing script originally posted. <?php //combines variables $eventYear, $eventMonth & eventDay to variable '$eventDate'. $eventYear = $_POST['eventYear']; $eventMonth = $_POST['eventMonth']; $eventDay = $_POST['eventDay']; $eventDate = "$eventYear-$eventMonth-$eventDay"; //assigns contents of 'listing_artist' to variable '$listing_artist'. $eventName = $_POST['eventName']; //assigns contents of 'listing_desc' to variable '$listing desc'. $eventDescLong = $_POST['eventDescLong']; //assigns contents of 'eventEntryFee' to variable '$eventEntryFee'. $eventEntryFee = $_POST['eventEntryFee']; // Include script to search for video content and resize it. include ('resize_video.php'); // Include database connection code. include ('dbConnect.php'); $queryTable = "INSERT INTO eventsTable ( eventDate, eventName, eventDescLong, eventEntryFee ) VALUES ( '$eventDate', '$eventName', '$eventDescLong', '$eventEntryFee' )"; $result = mysql_query($queryTable, $connection) or die (mysql_error()); mysql_close ($connection); include ('redirectToEdit.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213379 Share on other sites More sharing options...
.josh Posted May 10, 2011 Share Posted May 10, 2011 Cool story bro, but I meant for you to post an example of the actual value of $eventDescLong Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213386 Share on other sites More sharing options...
damnedgentleman Posted May 10, 2011 Author Share Posted May 10, 2011 Ah! That value is just a youtube iframe. In this instance: <iframe width="425" height="349" src="http://www.youtube.com/embed/oSxWqfayU9E" frameborder="0" allowfullscreen></iframe> I'd like the code to be able to recognise any video iframe. Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213387 Share on other sites More sharing options...
.josh Posted May 10, 2011 Share Posted May 10, 2011 $eventDescLong = '<iframe width="425" height="349" src="http://www.youtube.com/embed/oSxWqfayU9E" frameborder="0" allowfullscreen></iframe>'; $video = preg_replace('~width\s?=\s?["\'][^"\']+["\']~i', 'width="580"', $eventDescLong); $video = preg_replace('~height\s?=\s?["\'][^"\']+["\']~i', 'height="387"', $video); Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213391 Share on other sites More sharing options...
damnedgentleman Posted May 10, 2011 Author Share Posted May 10, 2011 That'd do it in this instance. However, some of the long event descriptions also contain descriptive text, as well as a video. For example: 'Conquering Animal Sound provided one of our most memorable shows in late 2010. Wilfully angular Scottish boy/girl duo with their excellent L.P, affection for Toy Keyboards, and their other worldly sounds. This is highly recommended! <iframe width="425" height="349" src="http://www.youtube.com/embed/4D_iv0Dyg-k" frameborder="0" allowfullscreen=""></iframe>' How would I get the script to scan the entry, and locate the appropriate part to replace? Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213393 Share on other sites More sharing options...
.josh Posted May 10, 2011 Share Posted May 10, 2011 Well, if you know your $eventDescLong variable is only ever gonna hold that one iframe, or more accurately, one place where you have a width=".." and height=".." then you can use the same patterns, though just work directly with $eventDescLong instead of using $video: $eventDescLong = preg_replace('~width\s?=\s?["\'][^"\']+["\']~i', 'width="580"', $eventDescLong); $eventDescLong = preg_replace('~height\s?=\s?["\'][^"\']+["\']~i', 'height="387"', $eventDescLong); But if you know you will have other things in $eventDescLong (like images) that will have a width=".." or height=".." then you can do this: $eventDescLong = preg_replace('~(<iframe[^>]*width\s?=\s?["\'])[^"\']+(["\'])~i', '${1}580${2}', $eventDescLong); $eventDescLong = preg_replace('~(<iframe[^>]*height\s?=\s?["\'])[^"\']+(["\'])~i', '${1}387${2}', $eventDescLong); Quote Link to comment https://forums.phpfreaks.com/topic/235976-trying-to-automate-video-resizing/#findComment-1213415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.