Szerző Téma: Youtube linkek beillesztése  (Megtekintve 811 alkalommal)

Youtube linkek beillesztése
« Dátum: 2017. Szeptember 09. - 18:24:49 »
0
Sziasztok! Például itt is betudok
 


   

 
 illeszteni youtube linkeket a szöveg közé. Nekem nem real-time kéne, hanem csak érzékelni és rendes így kiíratni. Valaki tudna segíteni?
 
(PHP nagyon jó lenne.)
« Utoljára szerkesztve: 2017. Szeptember 09. - 18:25:11 írta thegergo02 »

Youtube linkek beillesztése
« Válasz #1 Dátum: 2017. Szeptember 10. - 10:29:27 »
0
Szia nem igen értek hozzá, de ha BB kódra keresel rá akkor abból nem lehet kikövetkeztetni?  Mondom nem értek hozzá csak egy tipp. Pl YouTube embed BB code

Youtube linkek beillesztése
« Válasz #2 Dátum: 2017. Szeptember 10. - 10:33:27 »
0
Már megvan a megoldás! Google keresésekből összeraktam!
 

<?php
class textFormat {
       
        function autolink($string){
    // force http: on www.
    $string = str_ireplace( \"www.\", \"http://www.\", $string );
    // eliminate duplicates after force
    $string = str_ireplace( \"http://http://www.\", \"http://www.\", $string );
    $string = str_ireplace( \"https://http://www.\", \"https://www.\", $string );
    // The Regular Expression filter
    $reg_exUrl = \"/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/\";
    // Check if there is a url in the text
$m = preg_match_all($reg_exUrl, $string, $match);
if ($m) {
$links=$match[0];
for ($j=0;$j<$m;$j++) {
    if(substr($links[$j], 0, 19) == \'https://www.youtube\'){
    $string=str_replace($links[$j],\'<a href=\"\'.$links[$j].\'\" rel=\"nofollow\" target=\"_blank\">\'.$links[$j].\'</a>\',$string).\'<br /><iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"auto\" height=\"auto\" src=\"https://www.youtube.com/embed/\'.substr($links[$j], -11).\'\" frameborder=\"0\" allowFullScreen></iframe><br />\';
 
        }
    }
}
 

               return ($string);
 }
}
?>

 
A youtu.be-es linkeket nem támogatja, de nem kell sokat beleírni.
« Utoljára szerkesztve: 2017. Szeptember 14. - 17:27:43 írta thegergo02 »

Youtube linkek beillesztése
« Válasz #3 Dátum: 2017. Szeptember 14. - 17:28:30 »
0

       function autolink($string){
    // force http: on www.
    $string = str_ireplace( \"www.\", \"http://www.\", $string );
    // eliminate duplicates after force
    $string = str_ireplace( \"http://http://www.\", \"http://www.\", $string );
    $string = str_ireplace( \"https://http://www.\", \"https://www.\", $string );
    // The Regular Expression filter
    $reg_exUrl = \"/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/\";
    // Check if there is a url in the text
$m = preg_match_all($reg_exUrl, $string, $match);
if ($m) {
$links=$match[0];
for ($j=0;$j<$m;$j++) {
    if(substr($links[$j], 0, 19) == \'https://www.youtube\' || substr($links[$j], 0, 17) == \'https://youtu.be/\'){
    $string=str_replace($links[$j],\'<a href=\"\'.$links[$j].\'\" rel=\"nofollow\" target=\"_blank\">\'.$links[$j].\'</a>\',$string).\'<br /><iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"95%\" height=\"30%\" src=\"https://www.youtube.com/embed/\'.substr($links[$j], -11).\'\" frameborder=\"0\" allowFullScreen></iframe><br />\';
 
        } else if (substr($links[$j], 0, 25) == \'https://imgur.com/gallery\') {
            $string=str_replace($links[$j],\'<a href=\"\'.$links[$j].\'\" rel=\"nofollow\" target=\"_blank\">\'.$links[$j].\'</a>\',$string).\'<br /><center><img style=\"max-width:60%;max-height:60%;\" src=\"https://i.imgur.com/\'.substr($links[$j], strpos($links[$j], \'y/\')+2).\'.jpg\" </img></center><br />\';          
        } else if (substr($links[$j], 0, 17) == \'https://imgur.com\') {
            $string=str_replace($links[$j],\'<a href=\"\'.$links[$j].\'\" rel=\"nofollow\" target=\"_blank\">\'.$links[$j].\'</a>\',$string).\'<br /><center><img style=\"max-width:60%;max-height:60%;\" src=\"https://i.imgur.com/\'.substr($links[$j], strpos($links[$j], \'m/\')+2).\'.jpg\" </img></center><br />\';
        }
    }
}
 

               return ($string);
 }
}

 
imgurl-al kiegészítve. Meg (a tudomásom szerint) az összes youtube linket felismerni.

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal