Forum Gündemi:


Konu Başlığı : [PHP] YouTube Parser

*
Bu konu; tarihinde açılmış olup, 0 defa yorumlanmıştır.
Konu Sahibi : oxcakmak
Konuyu Değerlendir
  • 0 Oy - 0 Ortalama
  • 1
  • 2
  • 3
  • 4
  • 5
Çevrimdışı
Back-End Developer
******
105
mesajlar
82
konular
0
(Ticaret Puanı: )
Aug 2019
(Kayıt Tarihi)
#1
08-05-2019, 02:12 PM
Aşağıdaki kod bize youtube videosunun idsini verecektir:
PHP Kod:
function parseYouTubeURL($url){
    $pattern '#^(?:https?://)?';    # Optional URL scheme. Either http or https.
    $pattern .= '(?:www\.)?';         #  Optional www subdomain.
    $pattern .= '(?:';                #  Group host alternatives:
    $pattern .= 'youtu\.be/';       #    Either youtu.be,
    $pattern .= '|youtube\.com';    #    or youtube.com
    $pattern .= '(?:';              #    Group path alternatives:
    $pattern .= '/embed/';        #      Either /embed/,
    $pattern .= '|/v/';           #      or /v/,
    $pattern .= '|/watch\?v=';    #      or /watch?v=,
    $pattern .= '|/watch\?.+&v='#      or /watch?other_param&v=
    $pattern .= ')';                #    End path alternatives.
    $pattern .= ')';                  #  End host alternatives.
    $pattern .= '([\w-]{11})';        # 11 characters (Length of Youtube video ids).
    $pattern .= '(?:.+)?$#x';         # Optional other ending URL parameters.
    preg_match($pattern$url$matches);
    return (isset($matches[1])) ? $matches[1] : FALSE;



Kullanımı:
PHP Kod:
echo parseYouTubeURL("https://www.youtube.com/watch?v=7CMWXslGjco"); 


Çıktı:
PHP Kod:
#Video ID'si: 7CMWXslGjco 
[Linkleri yalnızca üyeler görüntüleyebilir.Sizde aramıza katılmak ister misiniz? Üye Olmak İçin Buraya Tıklayın.]


Foruma Git:


Görüntüleyenler: 1 Ziyaretçi