This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Retorna o id contido na url passada por parâmetro, | |
| * qualquer que seja a forma da url válida para o youtube | |
| * @method getIdYoutube | |
| * @see http://regex101.com/r/kW4bU8/1 | |
| * @author Wiliam Felisiak Passaglia Castilhos [[email protected]] | |
| * @date 2014-11-24 | |
| * @param [string] $url [url a ser analisada se contém um id do youtube válida] | |
| * @return [boolean|string] [retornará o id contido na url ou false caso não encontre] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * exemplo de funcionamento: http://regex101.com/r/kW4bU8/1 | |
| * Fará a comparação com expressão regular e no índice 3 do array, haverá o id do vídeo, que tem 11 caracteres | |
| * @method validarIdYoutube | |
| * @author Wiliam Felisiak Passaglia Castilhos [[email protected]] | |
| * @date 2014-11-21 | |
| * @param {string} url [url a ser analisada] | |
| * @return {boolean} [verdadeiro se for uma url que contenha um id válido] | |
| */ | |
| function validarIdYoutube(url){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @^.*(youtu.be\/|v\/|u\/\w+\/|embed|e\/|watch\?v|\?v=|\&v=)([^#\&\?]{11,11}).*@igm | |
| /* | |
| Tested examples: | |
| http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0 | |
| http://www.youtube.com/embed/0zM3nApSvMg?rel=0 | |
| http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index | |
| http://www.youtube.com/watch?v=0zM3nApSvMg | |
| http://youtu.be/0zM3nApSvMg | |
| http://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /(youtu(?:\.be|be\.com)\/(?:.*v(?:\/|=)|(?:.*\/)?)([\w'-]+))/i | |
| Tested examples: | |
| http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo | |
| http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel | |
| http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub | |
| http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I | |
| http://www.youtube.com/user/SilkRoadTheatre#p/a/u/2/6dwqZw0j_jY | |
| http://youtu.be/6dwqZw0j_jY | |
| http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be |