My site allows users to store Youtube url in my database table eg. http://www.youtube.com/watch?v=-S50SrP1zag&feature=rec-LGOUT-exp_fresh+div-1r-9-HM How to convert it to embed code format to display as like in community sites like Orkut
something like this: <?php $youtubeurl= (this comes from your db); $width=(set the video width); $height=(set the video height); ?> <object width="<?php echo $width; ?>" height="<?php echo $height; ?>" data="<?php echo $youtubeurl; ?>" type="application/x-shockwave-flash"> <param name="allowScriptAccess" value="never" /> <param name="allowNetworking" value="internal" /> <param name="wmode" value="transparent" /> <param name="movie" value="<?php echo $youtubeurl; ?>" /> <embed src="<?php echo $youtubeurl; ?>" type="application/x-shockwave-flash" width="<?php echo $width; ?>" height="<?php echo $height; ?>" allowscriptaccess="never" allownetworking="internal" wmode="transparent" /> </object> If you need to purify user text too, you can take a look at this cool library: http://htmlpurifier.org/
Thanks for reply but its not working: I tried by setting <?php $youtubeurl="http://www.youtube.com/watch?v=En4aZkij_q4&feature=rec-LGOUT-exp_fresh+div-1r-5-HM"; $width=200; $height=200; ?> <object width="<?php echo $width; ?>" height="<?php echo $height; ?>" data="<?php echo $youtubeurl; ?>" type="application/x-shockwave-flash"> <param name="allowScriptAccess" value="never" /> <param name="allowNetworking" value="internal" /> <param name="wmode" value="transparent" /> <param name="movie" value="<?php echo $youtubeurl; ?>" /> <embed src="<?php echo $youtubeurl; ?>" type="application/x-shockwave-flash" width="<?php echo $width; ?>" height="<?php echo $height; ?>" allowscriptaccess="never" allownetworking="internal" wmode="transparent" /> </object>