GTA Közösség - A magyar GTA fórum

Általános beszélgetés => Beszélgetés => Kérdések, Segítség => A témát indította: thegergo02 - 2017. Szeptember 09. - 18:24:49

Cím: Youtube linkek beillesztése
Írta: thegergo02 - 2017. Szeptember 09. - 18:24:49
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.)
Cím: Youtube linkek beillesztése
Írta: zsolti125 - 2017. Szeptember 10. - 10:29:27
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
Cím: Youtube linkek beillesztése
Írta: thegergo02 - 2017. Szeptember 10. - 10:33:27
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.
Cím: Youtube linkek beillesztése
Írta: thegergo02 - 2017. Szeptember 14. - 17:28:30

       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.