This example shows how to embed a YouTube or MetaCafe video in your webpage by providing the url of the video page. The example uses regular expression to get the id of the youtube video and id and name of the Metacafe video, which is used to generate the code for embedding the video. The generated code is compatible with the code provided by Youtube and metacafe.
To embed a video, pass the url of video page to the function embedVideo.
<?php
function embedVideo ( $url ){
if( preg_match ( "#http://(.*)\.youtube\.com/watch\?v=(.*)(&(.*))?#" , $url , $matches )){
?>
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/<?php echo $matches [ 2 ]; ?> &hl=en&fs=1"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/<?php echo $matches [ 2 ]; ?> &hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object>
<?php
}elseif( preg_match ( "#http://www\.metacafe\.com/watch/(([^/].*)/([^/].*))/?#" , $url , $matches )){
?>
<embed flashVars="playerVars=showStats=no|autoPlay=no|videoTitle=" src="http://www.metacafe.com/fplayer/<?php echo $matches [ 1 ]; ?> .swf" width="400" height="348" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"> </embed>
<?php
}
}
$youtubeVideo1 = 'http://in.youtube.com/watch?v=Km7PcdMzaN4' ;
$youtubeVideo2 = 'http://in.youtube.com/watch?v=xNi7QwAL3XY&feature=dir' ;
$metacafeVideo1 = 'http://www.metacafe.com/watch/2215104/amazing_video/' ;
$metacafeVideo2 = 'http://www.metacafe.com/watch/2204556/sensational_cars_of_the_future/' ;
embedVideo ( $youtubeVideo1 );
embedVideo ( $youtubeVideo2 );
embedVideo ( $metacafeVideo1 );
embedVideo ( $metacafeVideo2 );
?>
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance. Categories : HTML , PHP , HTML and PHP , Beginner Guides Multiple Select box, Select multiple Items from Menu.List box Categories : PHP , HTML and PHP , Beginner Guides Newbie Notes #1 - Making a form return to itself Categories : PHP , Beginner Guides , HTML and PHP mySQL/PHP/search with multientry
form and table output with colored rows Categories : PHP , Beginner Guides , MySQL , HTML and PHP , Databases Form Submission Using Array's Categories : PHP , HTML and PHP , Beginner Guides , Arrays Simple PHP Form Field Generator Categories : PHP , Beginner Guides , Form Processing , HTML and PHP How to Create a Shoutbox Using PHP & MySQL Categories : PHP , MySQL , Web Applications , Beginner Guides , HTML and PHP Kewl Date Example Categories : PHP , HTML and PHP , Date Time , CSS , Beginner Guides Newbie Notes #9 - Hyperlinking a post Categories : PHP , Java Script , HTML and PHP , Beginner Guides PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP , Email , PHP , Perl , HTML and PHP PHP based HTML rabbing Tools Categories : PHP , HTML and PHP , Tag Extractors , Regexps , Beginner Guides Using PHP im HTML image tags Categories : PHP , HTML and PHP , Graphics , Beginner Guides How to preset a text string in a textarea input field Categories : HTML , HTML and PHP , PHP , Beginner Guides PHP alternating the colors of table rows with style. Categories : PHP , HTML and PHP , CSS PHP function which gets all the data from a webpage into a string, we can perform regular expression functions on that data afterwards to get our desired data.
Categories : PHP , URLs , HTML and PHP