Jump to content

only allow this to insert into the database


Reaper0167

Recommended Posts

i have a text field which users can paste video embed code which will then get inserted into a database. what i'm looking to do is always have the same size, color(all the properties that are in the example below) no matter what the user changes in there embed code before they pasted it in the text field.

<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/ZuwP5C-1jJU&hl=en_US&fs=1&rel=0&color1=0xe1600f&color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZuwP5C-1jJU&hl=en_US&fs=1&rel=0&color1=0xe1600f&color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>

If anyone understands what I am explaining, is there a way to do this. I don't want the user to paste an embed code with a huge width and height. And even if they do, i would like to have it changed to the 320 by 265 on the fly. Thanks.

I've never had occasion to use DOMDocument before but here goes:

This pulls out the link sans query vars on the end like '&color1=0xe1600f'

and echo's this:

 

<?php
$s = '<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/ZuwP5C-1jJU&hl=en_US&fs=1&rel=0&color1=0xe1600f&color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZuwP5C-1jJU&hl=en_US&fs=1&rel=0&color1=0xe1600f&color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>?>';
$doc = new DOMDocument();
$doc->loadHTML($s);
foreach($doc->getElementsByTagName('param') as $obj) {
$name = $obj->getAttribute('name');
if($name == 'movie') {
	$url = $obj->getAttribute('value');

}
}
$endpos = strpos($url,'?');
if($endpos === false) {
$endpos = strpos($url,'&');
}
echo substr($url,0,$endpos);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.