remove &feature in youtube URL
Posted: Wed Jan 11, 2012 12:09 pm
hey guys, i have this php code, that i took from a guide on how to embed youtube URLs automatically on my website. The problem is though that the code only needs two thirds of the URL and therefore leaves the rest as normal text (it's from &feature to the end in the URL). Is it possible to add something to the script so it removes the URL-text, or does i have to write a comment above telling the users to manually delete it?
Code: Select all
$text=stripslashes($_POST['content']);
function show_youtube($text)
{
$VID_WID = 320;
$VID_HEI = 240;
for ($k=0; $k<9; $k++)
{
$text .= ' ';
$find = 'youtube.com/watch?v=';
$pos = strpos($text, $find);
if ($pos === false)
{
break;
}
$len = strlen($text);
for ($i=$pos; $i>=0; $i--)
{
if (substr($text, $i, 6) == 'http:/')
{
$pos1 = $i;
break;
}
}
for ($i=$pos; $i<$len; $i++)
{
if (in_array($text[$i], array('&', ' ', "\r", "\n", ',', "\t")))
{
$pos2 = $i;
break;
}
}
$link1 = substr($text, $pos1, $pos2 - $pos1);
$link2 = str_replace('/watch?v=', '/v/', $link1);
$embed = '<object width="' . $VID_WID . '" height="' . $VID_HEI . '">'.
'<param name="movie" value="' . $link2 . '"></param>'.
'<param name="allowFullScreen" value="true"></param>'.
'<param name="allowscriptaccess" value="always"></param>'.
'<embed src="' . $link2 . '" type="application/x-shockwave-flash" '.
'allowscriptaccess="always" allowfullscreen="true" '.
'width="' . $VID_WID . '" height="' . $VID_HEI . '"></embed></object>';
$text = str_replace($link1, $embed, $text);
}
return $text;
}