[ÇÖZÜLDÜ]Php Preg_Replace Sorunu
-
function convertYoutube($string) {
return preg_replace(
"/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
"<iframe width=\"99%\" height=\"315\" src=\"//www.youtube.com/embed/$2\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>",
$string
);
}
bunu şu şekil yapmak istiyorum mesela
<a href="https://www.youtube.com/watch?v=rIblEAvKRvk">https://www.youtube.com/watch?v=rIblEAvKRvk</a>
a hrefteki youtube adresini alıp embeb adresine dönüştürüp iframe içine koymak istiyorum nette araştırdım bulamadım ben de beceremedim.
Yardımcı olabilirseniz çok sevinirim
*******************************************************************************
ÇÖZÜLDÜ =
function a_href_youtube($text){
$search = '#<a(.*?)(?:href="https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch?.*?v=))([\w\-]{10,12}).*<\/a>#x';
$replace = '<center><iframe width="560" height="315" src="http://www.youtube.com/embed/$2" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></center>';
$text = preg_replace($search, $replace, $text);
return $text;
}
-
function convertYoutube($string) {
preg_match("/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", $string,$matches);
return "<iframe width=\"99%\" height=\"315\" src=\"//www.youtube.com/embed/$matches[2]\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>";
}preg replace yerine preg match kullanmak daha kolay
-
Çözmüşsun ama, Packagist te muhtemelen bu işi sadece youtu.be için değil her video platformu için yapan bir paket vardır hocam. Yerinde olsam ilk oraya bi bakardım.
-
yolbulucu bunu yazdı
Çözmüşsun ama, Packagist te muhtemelen bu işi sadece youtu.be için değil her video platformu için yapan bir paket vardır hocam. Yerinde olsam ilk oraya bi bakardım.
oha böyle bir siteden haberim yoktu tonla paket var hemen bakıyorum hocam. Çok sağol
EDİT =
BULDUM https://packagist.org/packages/dereuromark/media-embed
arkinfes tarafından 30/May/20 15:56 tarihinde düzenlenmiştir -
arkinfes bunu yazdıyolbulucu bunu yazdı
Çözmüşsun ama, Packagist te muhtemelen bu işi sadece youtu.be için değil her video platformu için yapan bir paket vardır hocam. Yerinde olsam ilk oraya bi bakardım.
oha böyle bir siteden haberim yoktu tonla paket var hemen bakıyorum hocam. Çok sağol
composerdaki paketler burdan geliyo iste. composer'ı biliyon di mi :D adsfasdf