I recently used this to allow people to paste the embed code into a field. It then extracted the YouTube ID code from the pasted code and re-created the HTML. Hope it helps and if anyone sees anything wrong with it, please let me know:
PHP Code:
<?php list ($g,$code,$g) = explode('youtube.com/', $_POST['youtube']); list($youtube_code,$g) = explode('"',$code); $youtube_code = preg_replace('/[^a-z&\/=0-9]/i','',$youtube_code); if (strlen($youtube_code) > 0) { $youtube_file_contents = '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/'.$youtube_code.'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/'.$youtube_code.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>'; } ?>
EDIT: I wrote that before I knew that strpos was faster. I don't know that that will be significant in this routine, however.
__________________
Jeremy Miller
Please login or register to view this content. Registration is FREE
Last edited by JeremyMiller; 06-25-2008 at 02:11 AM..
|