allowing users to enter messagein textarea.
user can post youtube video links anywhere in message.
wanted to modify this message in serverside php.
Convert all youtube links to youtube embed code.
Got below code from a site.
But it ignores all other than youtube links.
[CODE]<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’){
$input=$_POST[‘html’];
preg_match_all(‘#(http://www.youtube.com)?/(v/([-|~_0-9A-Za-z]+)|watch?v=([-|~_0-9A-Za-z]+)&?.*?)#i’,$input,$output);
foreach ($output[4] AS $video_id) {
if (!isset($video[$video_id])) {
$video[$video_id]=true;
$embed_code = ‘<object width=”300″ height=”300″><param name=”movie” value=”http://www.youtube.com/v/’.$video_id.’&hl=en&fs=1&”></param><param name=”allowFullScreen” value=”true”></param><param name=”allowscriptaccess” value=”always”></param><embed src=”http://www.youtube.com/v/’.$video_id.’&hl=en&fs=1&” type=”application/x-shockwave-flash” allowscriptaccess=”always” allowfullscreen=”true” width=”300″ height=”300″></embed></object>’;
echo $embed_code.'<br>’;
}
}
}
?>