0

次の関数を使用してYouTubeリンクをビデオとして表示していますが、問題は、複数のビデオを置き換える方法がわからないため、1つだけに制限するにはどうすればよいですか?

phpコード:

function embedYoutube($text)
{

    $pattern = '/[\\?\\&]v=([^\\?\\&]+)/';
    $replacement = '<div style="width:100%;float:left;margin-top:15px;margin-bottom:15px;"><iframe width="570" height="315" src=http://www.youtube.com/embed/$1 frameborder="0" allowfullscreen></iframe></div>';
    return preg_replace($pattern, $replacement, $text);

}
4

1 に答える 1

1
return preg_replace($pattern, $replace, $text, 1);

の4番目のパラメーターpreg_replaceは、置換の制限です。

于 2012-04-27T15:54:49.887 に答える