Reaper0167 Posted February 27, 2010 Share Posted February 27, 2010 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. Link to comment https://forums.phpfreaks.com/topic/193530-only-allow-this-to-insert-into-the-database/ Share on other sites More sharing options...
Reaper0167 Posted February 27, 2010 Author Share Posted February 27, 2010 I guess what I'm looking to do is just grab the param value and the embed source from what they pasted and then use that in my own custom embed code. Link to comment https://forums.phpfreaks.com/topic/193530-only-allow-this-to-insert-into-the-database/#findComment-1018817 Share on other sites More sharing options...
Reaper0167 Posted February 27, 2010 Author Share Posted February 27, 2010 anyone Link to comment https://forums.phpfreaks.com/topic/193530-only-allow-this-to-insert-into-the-database/#findComment-1019076 Share on other sites More sharing options...
F00Baron Posted February 27, 2010 Share Posted February 27, 2010 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); ?> Link to comment https://forums.phpfreaks.com/topic/193530-only-allow-this-to-insert-into-the-database/#findComment-1019092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.